一直在研究基本代码以在树莓派4和3上运行多台相机

import numpy as np
import cv2

cap = cv2.VideoCapture(1)

cap2 = cv2.VideoCapture(2)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    ret, frame2 = cap2.read()

    # Our operations on the frame come here
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('CAM 1',frame)
    cv2.imshow('CAM 2',frame2)
    #cv2.imshow('gray',gray)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break

 # When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

我一直在遇到以下错误
Traceback (most recent call last):
  File "/home/pi/Imageprocessing/webcamtest.py", line 16, in <module>
    cv2.imshow('CAM 1',frame)
cv2.error: OpenCV(3.4.3) /home/pi/opencv-3.4.3/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

尝试从(-1更改为2),但没有成功

其中一台相机打开,但显示图像。
摄像机可在网络浏览器上工作。
System : Raspberry Pi 4 4GB
OS: Buster
Python version : 2.7 and 3.7.3
Open CV version 3.4.3
Cameras: Logitech C310 720p

即使是Single Camera也不工作,并出现相同的错误

最佳答案

尝试从0(零)开始为相机编号:

cap = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)

关于python - Raspberry Pi 4上的断言失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59113188/

10-11 05:06