Grabbing V4L2 video from OF on a Linux machine

Basically my question is this: Using openframeworks on my linux machine, how can I capture a feed from a V4L2 device?

So I got this USB camera and I need it as a video input on a OF app on a linux machine.

When I play the video through V4L2, I can get the image I need, so I know that the camera works.

However, when I use ofVideoGrabber to retrieve the feed it looks very wrong.

On the ofVideoGrabber documentation page I saw this line:

'In Linux it uses by default unicap, although you can change to V4L through a #define in ofConstants in case some V4L devices don’t work properly with uncap.’

. But when I change the default to this:
#ifdef TARGET_LINUX
#define OF_VIDEO_PLAYER_V4L
the code won’t compile (on linux, though it does compile on my mac).

I have seen a couple forum posts about V4L2 and I also tried using the addon ofxV4L2 but these solutions seem outdated and aren’t even compiling on my machine.

Any ideas or suggestions?
Thanks!!

-Sam

1 Like

the video grabber in linux uses gfstreamer, you can check if it works with it with for example cheese which also uses gstreamer. also posting an example of what you mean by wrong would help figuring out what’s going on

Hi Arturo, I am working on this with Sam. Here is a picture of what it looks like coming into the videoGrabberExample.

Essentially the image is very dark. Whereas when we look at through qv4l2 we can see the image more clearly. Perhaps it’s a matter of controlling the settings from OF?

We tried to install your addon for the settings. But it wouldn’t compile because it couldn’t link to a 4l2 file. Maybe it is just a matter of relinking this file, but not quite sure how to do that in qt creator

something like guvcview will allow you to control the settings of any v4l2 device. to install it just:

sudo apt-get install guvcview

the ofxV4L2Settings addon has dependencies with a library and it’s not configured to add it automatically. you need to install the library first:

sudo apt-get install libv4l-dev

and then in the qt project add it as a dependency. in the .qbs file look for:

of.pkgConfigs: []

and change it to:

of.pkgConfigs: ['libv4l2']

Thanks for your help arturo, adding that library to the project worked!
We were able to increase the exposure on the feed and see the picture.

Now looking at the feed in cheese, it is very overexposed…
This won’t be a problem for our application, so I’m not going to worry about it.

Very appreciative,
-Sam