在 OpenCV 方法 VideoCapture.open() 中使用设备名称而不是 ID
我的 /dev
文件夹中有很多视频设备(例如 video1
、video2
、...、video9
)和一个始终指向有效设备的 /dev/video
(当然,可以更改).我想用 cv::Videocapture
用 OpenCV 打开 /dev/video
设备,发现只有两种打开方式:
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)
第一个打开一个文件,第二个打开/dev/video[device]
.
The first one opens a file and the second one opens /dev/video[device]
.
有没有办法像 cap = cv::VideoCapture("/dev/video");
?
推荐答案
使用当前的 OpenCV 3.2.0,您可以像这样创建新的捕获:
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)
使用 API Preference 打开视频文件或捕获设备或 IP 视频流以进行视频捕获.
VideoCapture (const String &filename, int apiPreference)
Open video file or a capturing device or a IP video stream for video capturing with API Preference.
这也可以通过 open 函数实现:
this is also possible with the open function:
cap.open("/dev/video20", cv::CAP_V4L);
我已经在 Kubuntu 16.10 下使用当前 git master 自行编译的 openCV 成功测试了这一点.
i have tested this successfully under Kubuntu 16.10 with self compiled openCV from current git master.
相关文章