How to send OpenCV video footage over Zeromq sockets?

ساخت وبلاگ

Vote count: 0

I've got a simple webcam which I read out using OpenCV and I'm now trying to send this video footage to a different (Python) program using ZeroMQ. So I've got the following simlpe script to read out the webcam and send it using a Zeromq socket:

import cv2
import os
import zmq
import base64
context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.connect('tcp://localhost:5555')
# init the camera
camera = cv2.VideoCapture(0)
while True: try: (grabbed, frame) = camera.read() # grab the current frame frame = cv2.resize(frame, (640, 480)) # resize the frame footage_socket.send_string(base64.b64encode(frame)) # Show the video in a window cv2.imshow("Frame", frame) # show the frame to our screen cv2.waitKey(1) # Display it at least one ms before going to the next frame except KeyboardInterrupt: camera.release() cv2.destroyAllWindows() print "nnBye byen" break

This works well in that it shows the video and doesn't give any errors.

I commented out the two lines which show the image (cv2.imshow() and cv2.waitKey(1)). I then started the script below in paralel. This second script should receive the video footage and show it.

import cv2
import zmq
import base64
import numpy as np
context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://*:5555')
footage_socket.setsockopt_string(zmq.SUBSCRIBE, unicode(''))
# camera = cv2.VideoCapture("output.avi")
while True: try: frame = footage_socket.recv_string() frame = np.fromstring(base64.b64decode(frame), dtype=np.uint8) cv2.imshow("Frame", frame) # show the frame to our screen cv2.waitKey(1) # Display it at least one ms before going to the next frame except KeyboardInterrupt: cv2.destroyAllWindows() break
print "nnBye byen"

Unfortunately, this freezes on cv2.waitKey(1).

Does anybody know what I'm doing wrong here? Do I need to decode the footage differently? All tips are welcome!

asked 17 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 300 تاريخ : شنبه 16 ارديبهشت 1396 ساعت: 12:51