Reputation: 33
I want to open a USB camera with OpenCV in C++ operating on Linux Mint 18.3.
The Camera is plugged in and works fine with the SoftwareSuite by Common Vision Blocks.
From command lsusb
I got the following output:
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
The first entry seems to be the camera because the entry doesn't exist if the camera is unplugged. But I don't understand why there isn't a name shown.
Then I found on the internet that the USB camera is found under the path:
/dev/v4l/by-id/ or /dev/v4l/by-path/
. The entry for /dev/v4l/by-id/
is:
usb-CNFEH73N3462520017B2_Integrated_Webcam_HD-video-index0
and the entry for /dev/v4l/by-path/
is:
pci-0000:00:14.0-usb-0:12:1.0-video-index0
So I want to open it with OpenCV by using:
VideoCapture
cap("/dev/v4l/by-id/usb-CNFEH73N3462520017B2_Integrated_Webcam_HD-video-index0");
I use Clion as an IDE and run it normally as root, but in both cases I get the following error:
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'
How can I open the USB camera and being on the right way to open it with dev/v4l/
?
Upvotes: 3
Views: 6565
Reputation: 4926
You should open a device by int id. Try with:
VideoCapture cap(0);
In fact, passing a string OpenCV expects to open a playback file, an MPEG file for example, as described in the documentation.
This is working but the problem is that the opened camera is the integrated camera, the one reported by lsusb
as:
Bus 001 Device 003: ID 1bcf:2b95 Sunplus Innovation Technology Inc.
which actually is /dev/video0
, linked by:
/dev/v4l/by-path/pci-0000:00:14.0-usb-0:12:1.0-video-index0
Instead the lsusb
entry listed as:
Bus 002 Device 005: ID 1ab2:0001
which is the externally plugged camera, seems not recognized as V4L device. I don't know "SoftwareSuite by Common Vision Blocks", so I have no idea, whether this software is able to work with it as RAW device.
Upvotes: 4