我无法让OpenCV检测到我的USB摄像头。当我使用其他工具时,系统似乎可以检测甚至拍照,但使用opencv它不起作用。
当我列出USB设备时:lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 006: ID 258a:002a SINO WEALTH Gaming KB
Bus 001 Device 005: ID 18f8:0f97 [Maxxter] Optical Gaming Mouse [Xtrem]
Bus 001 Device 004: ID 214b:7250 Huasheng Electronics USB2.0 HUB
Bus 001 Device 003: ID 214b:7250 Huasheng Electronics USB2.0 HUB
Bus 001 Device 010: ID 05a3:9230 ARC International Camera
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
当我尝试使用FSWEBCAM用相机捕捉图像时,它工作得很完美。fswebcam -r 1280x720 --no-banner test.jpg
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.
No input was specified, using the first.
--- Capturing frame...
Captured frame in 0.00 seconds.
--- Processing captured image...
Disabling banner.
Writing JPEG image to 'test.jpg'.
但是当我尝试使用opencv捕获图像时:
我尝试了/dev/videox
>>> import cv2
>>>
>>> cam = cv2.VideoCapture('/dev/video0')
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (1824) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module source reported: Could not read from resource.
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (914) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (501) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
还有那个号码
>>> import cv2
>>>
>>> cam = cv2.VideoCapture(0)
[ WARN:0] global ../modules/videoio/src/cap_gstreamer.cpp (961) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
>>>
我正在使用:
- Raspberry Pi 4 Model B Rev 1.5
- Raspbian
- Python 3.9.2
- pip 23.2.1
- python3-opencv==4.5.1(with 'sudo apt install python3-opencv')
(obs:我无法使用pip opencv-python安装opencv)
1条答案
按热度按时间mepcadol1#
好吧,我找到了一个对我有效的解决办法。我必须在VideoCapture中指定视频API,使用V4L2 API,最终代码如下所示:
希望能对有同样问题的人有所帮助:)