gpt4 book ai didi

python - Raspberry Pi 4 上的断言失败

转载 作者:行者123 更新时间:2023-12-03 05:11:57 25 4
gpt4 key购买 nike

一直致力于在树莓派 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

即使单摄像头也无法工作并出现相同的错误

最佳答案

尝试从 0(零)开始对相机进行编号:

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com