使用OpenCV和Raspberry Pi摄像头V2的问题

发布于 2025-01-22 07:34:06 字数 1101 浏览 2 评论 0原文

在过去的两个月中,我一直在使用以下代码,毫无问题,但是,就在昨天,我使用代码遇到了错误,我将详细介绍如下。所讨论的代码用于使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同展鸳鸯锦 2025-01-29 07:34:06

尝试一下。使用Raspberry Pi 4,Bullseye为我工作。您没有提到什么是文件名?

import cv2
import numpy as np

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)

while cap.isOpened():
    ret, frame = cap.read()
    cv2.imwrite('Atharva_Naik.jpg' , frame)
    cv2.imshow('Video', frame)
    cv2.waitKey(0)
       
cap.release()
cv2.destroyAllWindows()  

Try this. Worked for me Using Raspberry pi 4, Bullseye. You haven't mentioned what filename is?

import cv2
import numpy as np

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)

while cap.isOpened():
    ret, frame = cap.read()
    cv2.imwrite('Atharva_Naik.jpg' , frame)
    cv2.imshow('Video', frame)
    cv2.waitKey(0)
       
cap.release()
cv2.destroyAllWindows()  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文