我购买了两个网络摄像头(Logitech C310 HD Webcam),用于RaspberryPi(RPi 3 B +型号)。当我运行单个摄像机时,它们运行良好,但是当我尝试同时运行两个摄像机时却没有运行。我知道这可能是由于Raspberry Pi的电量不足所致,所以我购买了有源USB集线器(Power USB hub)。当我通过电源USB集线器将两个带树莓派的相机连接在一起时,它显示错误。
Unable to stop the stream: Invalid argument
OpenCV(3.4.1) Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/pi/opencv-3.4.1/modules/highgui/src/window.cpp, line 356
Traceback (most recent call last):
File "two cameras simu.py", line 7, in <module>
cv2.imshow('frame1',frame1)
cv2.error: OpenCV(3.4.1) /home/pi/opencv-3.4.1/modules/highgui/src/window.cpp:356: error: (-215) size.width>0 && size.height>0 in function imshow
我使用的代码是:
import cv2
import numpy as np
cam1 = cv2.VideoCapture(1)
cam2 = cv2.VideoCapture(2)
while (1):
_,frame1 = cam1.read()
cv2.imshow('frame1',frame1)
_,frame2 = cam2.read()
cv2.imshow('frame2',frame2)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cam1.release()
cam2.release()
cv2.destroyAllWindows()
虽然我在连接了电源USB集线器的笔记本电脑(在PyCharm中)中运行了相同的代码,但效果很好。
为什么在尝试用Raspberry Pi运行两台相机时出现错误?如何使用Raspberry Pi运行两个网络摄像头。
答案 0 :(得分:0)
尝试在顶部添加
The action cannot be completed because the file is open in Python
然后例如相应地更改摄像机的输入源
from imutils import VideoStream
import imutils
希望这可以解决您的问题