使用OpenCV和Raspberry Pi摄像头V2的问题
在过去的两个月中,我一直在使用以下代码,毫无问题,但是,就在昨天,我使用代码遇到了错误,我将详细介绍如下。所讨论的代码用于使用Raspberry Pi摄像头拍摄对象的照片。
我使用以下代码初始化了Raspberry Pi摄像机V2:
cap = cv2.VideoCapture('/dev/video0', cv2.CAP_V4L)
#set dimensions
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2560)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1440)
之后,我使用以下代码来将图像写入文件名:
ret, frame = cap.read()
cv2.imwrite(fileName , frame)
我最近遇到了以下错误:
[ WARN:[email protected]] global /io/opencv/modules/videoio/src/cap_v4l.cpp (1000) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
Traceback (most recent call last):
File "/home/pi/Documents/proj_trash_can/main.py", line 55, in <module>
clickPicture(cam_capture, filename)
File "/home/pi/Documents/proj_trash_can/cam.py", line 22, in clickPicture
cv2.imwrite(fileName , frame)
cv2.error: OpenCV(4.5.5) /io/opencv/modules/imgcodecs/src/loadsave.cpp:801: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'
I had been using the following code for the past two months with no problem whatsoever, however, just yesterday I have been getting errors using the code which I will detail as follows. The code in question is used to take photos of objects using the raspberry pi camera.
I initialize the raspberry pi camera v2 using the following code:
cap = cv2.VideoCapture('/dev/video0', cv2.CAP_V4L)
#set dimensions
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2560)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1440)
After which I take a photo from the camera and write the image to a filename using the following lines of code:
ret, frame = cap.read()
cv2.imwrite(fileName , frame)
I have been getting the following error quite recently:
[ WARN:[email protected]] global /io/opencv/modules/videoio/src/cap_v4l.cpp (1000) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
Traceback (most recent call last):
File "/home/pi/Documents/proj_trash_can/main.py", line 55, in <module>
clickPicture(cam_capture, filename)
File "/home/pi/Documents/proj_trash_can/cam.py", line 22, in clickPicture
cv2.imwrite(fileName , frame)
cv2.error: OpenCV(4.5.5) /io/opencv/modules/imgcodecs/src/loadsave.cpp:801: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下。使用Raspberry Pi 4,Bullseye为我工作。您没有提到什么是文件名?
Try this. Worked for me Using Raspberry pi 4, Bullseye. You haven't mentioned what filename is?