Open usb camera using name instead of index in openCV3.2

asked 2018-01-08 05:07:01 -0600

alexMm1 gravatar image

Hi all,

I have an issue with my USB camera. When I plug it into my system, it creates two different links: /dev/video0 and /dev/video1. Sometimes, it happens that the video frames are indifferently passed to index 0 or index 1.

I know how to detect the correct video source an, for this reason, I create a virtual video device that is a map of that source.

Now, I would like to know if it is possible to call the VideoCapture function, passing directly the name of the device, e.g., /dev/videoMine instead of the index.

I already tried something like:

VideoCapture cap("/dev/videoMine", CAP_V4L);

but it does not work.

thanks

edit retag flag offensive close merge delete

Comments

I don't think it is possible if I understand well doc

LBerger gravatar imageLBerger ( 2018-01-08 06:51:37 -0600 )edit

videoMine is folder or filename? But this should be CAP_V4L2 instead of CAP_V4L?

supra56 gravatar imagesupra56 ( 2018-01-08 08:46:18 -0600 )edit

videoMine is the name of the device I re-mapped.... suppose /dev/video0 in /dev/videoMine

alexMm1 gravatar imagealexMm1 ( 2018-01-08 10:58:11 -0600 )edit

Try to open /dev/v4l/by-id/[camera-id].

kbarni gravatar imagekbarni ( 2018-01-08 11:53:21 -0600 )edit

mmm...@kbarni, in this way I have to know the cam id...by the way, it does not work

alexMm1 gravatar imagealexMm1 ( 2018-01-09 03:24:51 -0600 )edit

Normally a webcam should create a single device (like /dev/video0). It also creates links to this device using the device ID and the connection port (these might be useful if you want to identify a particular device when several cameras are connected - e.g. you want to do stereo vision and don't know if the video0 is the left or right camera).

In OpenCV you can use any of these solutions to open the camera:

VideoCapture cap(0);
VideoCapture cap("/dev/video0");
VideoCapture cap("/dev/v4l/by-id/usb-046d_08ce_5306FC91-video-index0");
VideoCapture cap("/dev/v4l/by-path/pci-0000:00:14.0-usb-0:7:1.0-video-index0");

Tested all and working. If you have problems, maybe the problem is elsewhere.

kbarni gravatar imagekbarni ( 2018-01-09 04:18:45 -0600 )edit