我想在 Linux Mint 18.3 上使用 C++ 语言的 OpenCV 打开 USB 摄像头。
相机已插入并可与 Common Vision Blocks 的 SoftwareSuite 配合使用。
来自命令lsusb
我得到以下输出:
Bus 002 Device 005: ID 1ab2:0001
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 0cf3:e300 Atheros Communications, Inc.
Bus 001 Device 003: ID 1bcf:2b95 Sunplus Innovation Technology Inc.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
第一个条目似乎是相机,因为如果拔掉相机插头,该条目就不存在。但我不明白为什么没有显示名字。
然后我在网上查到USB摄像头在以下路径下:/dev/v4l/by-id/ or /dev/v4l/by-path/
。条目为/dev/v4l/by-id/
is:
usb-CNFEH73N3462520017B2_Integrated_Webcam_HD-video-index0
和条目/dev/v4l/by-path/
is:
pci-0000:00:14.0-usb-0:12:1.0-video-index0
所以我想用 OpenCV 打开它:
VideoCapture
cap("/dev/v4l/by-id/usb-CNFEH73N3462520017B2_Integrated_Webcam_HD-video-index0");
我使用 Clion 作为 IDE 并以 root 身份正常运行它,但在这两种情况下我都会收到以下错误:
GStreamer Plugin: Embedded video playback halted; module source reported: Could not read from resource.
OpenCV Error: Unspecified error (GStreamer: unable to start pipeline) in cvCaptureFromCAM_GStreamer
/opencv-3.0.0/modules/videoio/src/cap_gstreamer.cpp, line 773 terminate called after throwing an instance of 'cv::Exception'
如何打开 USB 摄像头并以正确的方式打开它dev/v4l/
?