Raspberry Pi 4断言失败

问题描述 投票:2回答:1

一直在研究基本代码,以便在树莓派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

甚至单台相机都无法工作,并且出现相同的错误

python opencv
1个回答
1
投票

[尝试从0(零)开始对摄像机编号:

cap = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)
© www.soinside.com 2019 - 2024. All rights reserved.