Skip to content

Instantly share code, notes, and snippets.

@timothymugayi
Created June 5, 2020 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timothymugayi/8605f18f3b83bf240b1d681d641cec80 to your computer and use it in GitHub Desktop.
Save timothymugayi/8605f18f3b83bf240b1d681d641cec80 to your computer and use it in GitHub Desktop.
import cv2
import zmq
context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.bind("tcp://*: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)
footage_socket.send(buffer)
except KeyboardInterrupt:
camera.release()
cv2.destroyAllWindows()
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment