Python 我正在尝试使用imagezmq和opencv制作一个视频聊天应用程序
代码如下: 服务器:Python 我正在尝试使用imagezmq和opencv制作一个视频聊天应用程序,python,python-3.x,opencv,zeromq,Python,Python 3.x,Opencv,Zeromq,代码如下: 服务器: import cv2 import numpy as np import imagezmq image_hub = imagezmq.ImageHub() while True: # show streamed images until Ctrl-C win_name = "Feed" image = image_hub.recv_image() img = cv2.imdecode(image, 1) cv2.imshow(win
import cv2
import numpy as np
import imagezmq
image_hub = imagezmq.ImageHub()
while True: # show streamed images until Ctrl-C
win_name = "Feed"
image = image_hub.recv_image()
img = cv2.imdecode(image, 1)
cv2.imshow(win_name, img)
cv2.waitKey(1)
image_hub.send_reply(b'OK')
客户:
import socket
import time
from imutils.video import VideoStream
import imagezmq
import cv2
import numpy as np
sender = imagezmq.ImageSender(connect_to='tcp://192.168.0.12:5555')
vs = VideoStream(src=0).start()
time.sleep(2.0)
while True: # send images as stream until Ctrl-C
frame = vs.read()
img_arr = np.array(bytearray(frame))
sender.send_image("Img",img_arr)
我得到了一个错误:
img = cv2.imdecode(image, 1)
TypeError: Expected Ptr<cv::UMat> for argument 'buf'
img=cv2.imdecode(图1)
TypeError:参数“buf”应为Ptr
在服务器上
我在网上查过了,但找不到合适的答案
注意:我在这方面没有太多经验。根据imagezmq的说法,不使用任何imdecode,也不使用任何bytearray()
调用
您只需来回发送numpy阵列
此外,我建议不要使用
imutils
,尤其是VideoStream
包装器。使用OpenCV的视频捕获
。在尝试读取之前,请检查是否有isOpened()
。当使用ok,frame=cap.read()
读取时,检查读取帧是否ok
,否则中断读取循环并丢弃frame
中的值!谢谢你的帮助。现在可以了!