Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OpenCV support v4l2?

Tags:

opencv

v4l2

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?

like image 514
Lord Spectre Avatar asked Sep 17 '25 10:09

Lord Spectre


2 Answers

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

like image 188
tinker tailor Avatar answered Sep 19 '25 07:09

tinker tailor


OpenCV does support V4L2, but maybe not by default.

Download OpenCV's source code and make sure you have v4l2 headers and libraries installed on your system.

After configuring OpenCV with cmake, check it's output:

--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.0)
--     FFMPEG:                      YES
--       codec:                     YES (ver Unknown)
--       format:                    YES (ver Unknown)
--       util:                      YES (ver Unknown)
--       swscale:                   YES (ver Unknown)
--       gentoo-style:              YES
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     QuickTime:                   NO
--     QTKit:                       YES
--     V4L/V4L2:                    NO/NO

If you notice the output above, OpenCV won't be build with support to V4L/V4L2 on my system because I don't have the necessary development files installed.

like image 42
karlphillip Avatar answered Sep 19 '25 07:09

karlphillip