You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import base64
|
|
|
|
import cv2
|
|
|
|
import zmq
|
|
|
|
|
|
|
|
context = zmq.Context()
|
|
|
|
|
|
|
|
socket = context.socket(zmq.REP)
|
|
|
|
socket.bind("tcp://*:4444")
|
|
|
|
while True:
|
|
|
|
client_ip = socket.recv()
|
|
|
|
break
|
|
|
|
|
|
|
|
footage_socket = context.socket(zmq.PUB)
|
|
|
|
footage_socket.connect('tcp://' + client_ip.decode() + ':5555')
|
|
|
|
|
|
|
|
camera = cv2.VideoCapture(0) # init the camera
|
|
|
|
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
grabbed, frame = camera.read() # grab the current frame
|
|
|
|
frame = cv2.resize(frame, (640, 480)) # resize the frame
|
|
|
|
encoded, buffer = cv2.imencode('.jpg', frame)
|
|
|
|
jpg_as_text = base64.b64encode(buffer)
|
|
|
|
footage_socket.send(jpg_as_text)
|
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
camera.release()
|
|
|
|
cv2.destroyAllWindows()
|
|
|
|
break
|