Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我正在尝试使用imagezmq和opencv制作一个视频聊天应用程序_Python_Python 3.x_Opencv_Zeromq - Fatal编程技术网

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
中的值!谢谢你的帮助。现在可以了!