Using device name instead of ID in OpenCV method VideoCapture.open()
c++, camera, opencv, video, video-capture
Solution
with current OpenCV 3.2.0 you can create a new capture like this:
cv::VideoCapture cap("/dev/video20", cv::CAP_V4L);
its one of the additional constructors:
VideoCapture (const String &filename, int apiPreference) Open video file or a capturing device or a IP video stream for video capturing with API Preference.
this is also possible with the open function:
cap.open("/dev/video20", cv::CAP_V4L);
i have tested this successfully under Kubuntu 16.10 with self compiled openCV from current git master.
Problem
I have a lot of video devices in my `/dev` folder (e.g. `video1`, `video2`, ..., `video9`) and one `/dev/video` which is always pointing to the valid device (which, of course, can change). I want to open the `/dev/video` device with OpenCV using `cv::Videocapture` and realized that there are only two ways to open it: ``` VideoCapture::VideoCapture(const string& filename) VideoCapture::VideoCapture(int device) ``` The first one opens a file and the second one opens `/dev/video[device]`. Is there any way to do something like `cap = cv::VideoCapture("/dev/video");`?