2019-08-04 16:29:57 +02:00
|
|
|
import io
|
|
|
|
import socket
|
|
|
|
import struct
|
|
|
|
import time
|
|
|
|
import cv2
|
|
|
|
|
|
|
|
# Connect a client socket to my_server:8000 (change my_server to the
|
|
|
|
# hostname of your server)
|
|
|
|
client_socket = socket.socket()
|
2019-08-04 17:05:59 +02:00
|
|
|
client_socket.connect(('192.168.1.107', 8000))
|
2019-08-04 16:29:57 +02:00
|
|
|
|
|
|
|
# Make a file-like object out of the connection
|
|
|
|
connection = client_socket.makefile('wb')
|
|
|
|
try:
|
2019-08-04 16:37:40 +02:00
|
|
|
cap = cv2.VideoCapture("run.mp4")
|
2019-08-04 16:29:57 +02:00
|
|
|
|
2019-08-04 16:37:40 +02:00
|
|
|
while True:
|
|
|
|
ret, frame = cap.read()
|
|
|
|
|
2019-08-04 17:05:59 +02:00
|
|
|
if frame is None:
|
2019-08-04 16:37:40 +02:00
|
|
|
break
|
2019-08-04 17:05:59 +02:00
|
|
|
print(type(frame))
|
|
|
|
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
|
|
|
print(type(gray))
|
|
|
|
_, image = cv2.imencode('.jpg', gray)
|
|
|
|
print(type(image))
|
2019-08-04 16:37:40 +02:00
|
|
|
stream = image.tobytes()
|
2019-08-04 17:05:59 +02:00
|
|
|
print(type(stream))
|
2019-08-04 16:37:40 +02:00
|
|
|
|
|
|
|
# Write the length of the capture to the stream and flush to
|
|
|
|
# ensure it actually gets sent
|
|
|
|
connection.write(struct.pack('<L', stream.tell()))
|
|
|
|
connection.flush()
|
|
|
|
# Rewind the stream and send the image data over the wire
|
|
|
|
stream.seek(0)
|
|
|
|
connection.write(stream.read())
|
|
|
|
# If we've been capturing for more than 30 seconds, quit
|
|
|
|
if time.time() - start > 30:
|
|
|
|
break
|
|
|
|
# Reset the stream for the next capture
|
|
|
|
stream.seek(0)
|
|
|
|
stream.truncate()
|
2019-08-04 16:29:57 +02:00
|
|
|
# Write a length of zero to the stream to signal we're done
|
|
|
|
connection.write(struct.pack('<L', 0))
|
|
|
|
finally:
|
|
|
|
connection.close()
|
|
|
|
client_socket.close()
|