我正在使用 OpenCV 从大约每半分钟的帧流中读取图像并显示它。代码是:
import cv2
import zmq
import base64
import numpy as np
context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://An IP')
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))
cv2.startWindowThread()
cv2.namedWindow("Stream")
while True:
try:
frame= footage_socket.recv_string()
img= base64.b64decode(frame)
npimg= np.fromstring(img, dtype=np.uint8)
decoded= cv2.imdecode(npimg, 1)
cv2.imshow("Stream", decoded)
except KeyboardInterrupt:
break
cv2.destroyAllWindows()
按Ctrl+C似乎什么也没做。
我尝试添加:
if cv2.waitKey(1)& 0xFF == ord('q'):
break
但我得到了错误Attempt to unlock mutex that was not locked Aborted
,我的程序根本没有运行。