testing video grabbing under linux

Video grabbing under linux is a bit problematic, due to the variety of available protocols and the lack of drivers. This thread, tries to explain how to know if your device is supported under linux. I’ll present some tools that should work with every kind of device, if your camera works with some of this software but not under openframeworks, please post a message with your device model, the program it works with, and the output of the videoGrabbingExample.

Webcams: v4l/v4l2
For webcams the most common standard is v4l, that although is an old standard and has some design failures, it’s the most used nowadays. The new one is v4l2. Normally every camera that supports v4l2, also support v4l.

To try if those cameras are supported you can use:

Camorama: only for v4l devices, under debian and derivates you can install it with:

sudo apt-get install camorama

Ekiga: is the videoconference software that ships with most of the gnome based distributions, under edit > preferences > devices > video devices, you can select your video device, it works both for v4l and v4l2

UCView: see below

Firewire devices:
Coriander: For raw firewire devices, (not dv cams) you can use this. A little bit ugly but it’s supposed to work with almost every 1394 device. Under debian derivates you can install it with:

sudo apt-get install coriander

UCView: see below

DV devices
Kino: The most known program to work with dv cameras is kino, a non linear video editing software for linux. To install it:

sudo apt-get install kino

UCView
As far as I know this is the only program that works with v4l, v4l2 and raw firewire devices. Also I’ve been talking with Arne Caspari (the unicap developer) and he is going to set up a simple DV module without transportation (no support for forwarding, playing… the tape) so I can extend it to our needs. Openframeworks 0.05, will ship with the same library that this program use, so if your device works with it, it have to work under the next openframeworks version. It’s also really useful to adjust your device properties before working with it (ie: deactivating auto mode for artificial vision apps).

You can download it from

http://www.unicap-imaging.org/download.htm

If you use ubuntu, the easiest way to install it, is to follow the instructions in

http://www.unicap-imaging.org/using-repository.htm

and then

sudo apt-get install ucview

Opencv
opencv provides video grabbing functions for v4l/v4l2 and raw firewire devices under linux:

  
#include "highgui.h"  
#include "cv.h"  
#include "cxcore.h"  
#include "cvaux.h"  
  
int main( int argc, const char* argv[] ){  
    CvCapture * vidGrabber= cvCreateCameraCapture( device_id );  
    cvSetCaptureProperty(vidGrabber,CV_CAP_PROP_FRAME_WIDTH,width);  
    cvSetCaptureProperty(vidGrabber,CV_CAP_PROP_FRAME_HEIGHT,height);  
  
    while(true){  
        IplImage* image = cvQueryFrame(vidGrabber);  
        // do whatever you want with image  
        ...  
    }  
}  

where device_id is:

autodetect: 0
v4l/v4l2: 200
firewire: 300

Add device number to that if you have more than one of that kind. ie: if you have two firewire devices, to open the second one, device_id will be 301.

hope that helps

arturo

Tested with and without Compiz, on Ubuntu Gutsy 7.10 running KDE 3.5.8. The webcam works fine with Camorama, Cheese, Kopete etc. When I try to run the videoGrabbing example, the CPU is constantly at 100%, a full screen window is created but I don’t see anything. On the console, I get:

choosing device /dev/video0
V4L : Name = ‘Creative NX’
V4L : Dimensions (176 x 144) - (352 x 288)
V4L : Capability :

  • CAPTURE
    V4L : Brightness = 32768
    V4L : Hue = 0
    V4L : Colour = 0
    V4L : Depth = 24 bits
    V4L : Palette = VIDEO_PALETTE_RGB24
    V4L : Changed current palette to VIDEO_PALETTE_RGB24
    V4L : Video size changed to width=320 height=240

So it definitely seems to identify the camera correctly. I straced the application and saw TONS of sched_yield() calls. I can attach a detailed trace if needed.

thanks arturo for the info - that’s awesome / super helpful -

CPU is constantly at 100%

this is a product of glut (glut apps try to run as fast as possible) so not something to worry about. frame rate (how quickly the app runs) is a better measure of “stress” on the system. when your OF app is working harder you will see the frame rate drop - and cpu usage will stay the same.

we should have 0.05 soon, the problem is getting all the addon stuff done for every compiler / platform. I just finished devcpp yesterday and will do VS/linux today. we are happy to post it soon and also add in the unicap capture code. I will try to add the unicap to svn today.

-z

diwakergupta:
Umm, I’ve got a feeling that’s another case of the video code being commented out… a mistake from the last OF export. Try opening the testApp.cpp source code of the videograbber app, and check for any sections commented out, and uncomment them…because your webcam has been detected by OF and it supports RGB so you should be fine.

@grimus: hah, that fixed it, thanks! I wonder why I didn’t look at the source code myself :slight_smile:

:oops:

sorry ! will be fixed in 0.05 …

glad it’s up and running

take care - z

I can confirm that the OF 0.04 version of the videoGrabber works with V4L but only for USB webcams with RGB24 output. I was able to test that with a borrowed webcam.

I have a firewire webcam but V4L doesn’t do firewire so I tried using coriander to create a V4L stream from the firewire input but that didn’t work out.

I also have a USB webcam but it only outputs YUV420 so that didn’t work out either as the conversion routines don’t exist yet in v4lutils . I tried searching for YUV420 to RGB routines on the web to copy and paste into v4lutils code but what I found was a little too complicated for me.

So I’m kind of stuck right now. I understand from Arturo’s post that the OF 0.05 version of the videoGrabber code will use the unicap library instead of V4L, is that correct? That sounds good since I tried ucview and it did recognize my firewire camera. Is there any chance I could try out the new videoGrabber code now?

I’m doing the port now (we’ve done mac and pc) and I will try to upload what arturo has as I go in the next few days. it would be great to have someone else to look at it. I don’t have it in front of me. but as soon as I do I can upload it. arturo might be able to jump in too now.

other linux things I could use help with (and I just throw this out there for anyone)…

a) I could also use help w/ anyone that has a 64 bit system and would like to compile libraries :slight_smile:

d) also, I am trying to get up and running with some kind of virtualization software so I can run my linux install in windows at the same time, but vmworkstation seems to kill my xserver conf stuff (it doesn’t find the monitor or graphics card, etc). anyone have experience running linux side by side w/ windows? I just want to not reboot to test stuff…

thanks!
zach

Hi Jaime,
I made a fix to the conversion routines to support YUV420P, and I have a feeling this works with YUV420 as well.
This was buried deep in the Linux users thread:
http://forum.openframeworks.cc/t/linux-users/61/36

Hi

Since there have been many changes since the last version including unicap, i can’t upload a version including it, but send me the last version if you need to test it, i’ll have some time this week. Also I’ve sent you a mail related to unicap.

Zach I sent you the 64bit compiled libraries for most of the addons, if you need to compile something more just tell me, i haven’t a 64 bit version just now, but i can install it in a partition if nobody else can.

As of the virtualization, I usually use vitualbox, it’s opensource and doesn’t have some problems that vmware have under linux with fullscreen:

http://www.virtualbox.org

Zach, re-reading your post about virtualization, perhaps you are trying to use your local install from vmware?

If so it’s normal that xserver doesn’t work, as virtualization solutions also virtualize the graphics card. If you’re under ubuntu (i think so), try:

sudo dpkg-reconfigure -phigh xserver-xorg

from the command line, it will configure xserver to use the virtual video card, but you will have to do the same when you boot from the partition.

you can make a backup of /etc/X11/xorg.conf before doing the reconfigure and then you only have to switch this file to boot from local/virtual.

If you’re going to use it frequently, I’d recomend that you make a fresh install for the virtual machine instead of using the local copy.

Zach, re-reading your post about virtualization, perhaps you are trying to use your local install from vmware?

yep exactly, I have ubuntu on my laptop, but would like to be able not have to reboot as I go back and forth between compiling…

as virtualization solutions also virtualize the graphics card. If you’re under ubuntu (i think so),

that would explain what was happenening. do you know if the virutalized card has opengl support, ie, would I be able to run OF apps from within vmware?

If you’re going to use it frequently, I’d recomend that you make a fresh install for the virtual machine instead of using the local copy.

thanks for the instructions. I’ll give it a try now…

for another install, space is an issue, but maybe I’ll just use a pen drive for a copy of linux I can run on the fly for testing / compiling…

thanks much !!
zach

for another install, space is an issue, but maybe I’ll just use a pen drive for a copy of linux I can run on the fly for testing / compiling…

You don’t need another partition to install a virtual machine, it can use a file as a disk image.

that would explain what was happenening. do you know if the virutalized card has opengl support, ie, would I be able to run OF apps from within vmware?

Not really sure, but i don’t think that the vmware emulated card has opengl support. parallels virtualization for mac supports windows opengl, but the windows version doesn’t support it. Under virtualbox it’s planed to support it but don’t really now if it’s already implemented:

http://www.virtualbox.org/ticket/475

Oh, and also important: every virtualization solution has it’s own set of tools (drivers…) you have to install this, once you have configured the virtual machine for everything to work properly. Usually you can do it from some option in the menus when the vm is on.

Hey arturo,

Just been testing the unicap based 005 examples on my laptop (Asus F9s with built in webcam).

After getting one successful frame I get a freeze at unicap_wait_buffer in getFrameUC - it looks like that function locks till a new buffer is available but in my case it seems no new buffer comes in.

Obviously this might be quite difficult for you to debug - but maybe you have an idea of what it could be)

The previous V4L method for grabbing in openFrameworks on linux worked fine for me - so it seems like an issue with unicap.

Let me know if there is any tests I can run!

Cheers,
Theo

Hi Theo

Can you upload the code and libs you’re using, I don’t have the last version.

Also can you open a console and write:

lsusb

and post the output.

Also if you can try ucview, the instructions are on the first post.

hi arturo,

unofficial 0.05 for linux is here / it’s the codeblocks version with fixes that should make it work on all versions of codeblocks. there is also a clever hack to make apps run from within CB. check out the readme:

http://www.openframeworks.cc/files/005–…-fat.tar.gz

as you know (since you told me!) you need libraw1394-dev.

we may put in both v4l and unicap and let people choose with a #define, since theo’s problem only occurs with unicap – it’d be good to have a choice, while we get feedback on what works, doesn’t etc…

take care!!
zach

Hey Zach,
If you do include the old V4L, can you make sure it’s got the updated YUV420 conversion routines?
http://www.digitalstar.net/openframeworks/video.zip
Thanks!

oh snaps, good call.

have put everything up (with V4L switchable) already but will patch it this morning…

thanks!!!
zach

[quote author=“zach”]
other linux things I could use help with (and I just throw this out there for anyone)…

a) I could also use help w/ anyone that has a 64 bit system and would like to compile libraries :slight_smile: I’ll grab yesterday’s 0.05_cb RC package and start hacking away at it. Do you have available either the version info or the sources for the libraries you have used in the RC package?

I’ve left a reply note about the solution I’ve found for this issue on the other post.

There’s an installation guide for Ubuntu 7.10 on my 0.04_cb-ofp workshop package. It’s for the svn version of code::blocks but I think the steps should be similar for the official C::B 8.02 binary. I’ll setup a test chroot to see if there are any differences and post the installation doc shortly.

Cheers,
P.

awesome, here’s the releases, but there will be a few changes shortly:

http://www.openframeworks.cc/versions/p-…-FAT.tar.gz
http://www.openframeworks.cc/versions/p-…–cb.tar.gz

there will be two changes:

a) adding V4L fixes from grimus
b) opencv cvcolorImage has a small bug (r g b order is wrong in the planar functions)

I’m gonna fix those changes and reupload in a second… arturo crafted an installation script in the “scripts” that should work well – haven’t had a chance to check it yet. in scripts there is also build all and clean all.

thanks!!
zach