Does OpenCV support v4l2?

Lord Spectre picture Lord Spectre · Mar 15, 2013 · Viewed 8.4k times · Source

I'm writing a Python program using OpenCV, but I cannot capture images from v4l2 cameras.

I tried with both a PS2 EyeToy and Droidcam (Android virtual webcam), which are both using v4l2, and none of them work: cv.CaptureFromCAM(0) only returns None.

I can use both webcams in other programs (tried VLC and Kamerka).

I guess that OpenCV supports v4l only, not v4l2.

How can I solve this problem? Does a v4l2->v4l converter exist?

EDIT: I read that cv.CaptureFromFile uses ffmpeg to decode video files. Is it possible to manually specify a format, so I can use ffmpeg's video4linux2 demuxer?

Answer

tinker tailor picture tinker tailor · Jun 18, 2017

For OpenCV 3.2.0, including the following in the cmake options worked for me

from https://github.com/opencv/opencv/issues/7974

-DWITH_V4L=ON 
-DWITH_LIBV4L=ON

I'm less sure if this one had an affect, but from VideoCapture Does Not Work in Anaconda

-DWITH_FFMPEG=1

Including all 3 in my cmake options seemed to be what finally made mine work