Linux webcam capture

Help
David
2010-09-05
2013-05-09
  • David
    David
    2010-09-05

    I have some USB webcams in Linux and I wanted to try the CaptureApp example.  In one place in the documentation, it seems to imply that USB webcams are supported by setting the USE_V4L variable in the base makefile:

    "USE_V4L
    An interface to Video for Linux (V4L) enables the control of most USB cameras (e.g. webcams). The class CV4LCapture implements the capture module. "

    Why can't I seem to get my webcams to work with the V4L interface and CaptureApp (it seems to want a 1394 camera)?

    Thanks in advance,

          Dave

     
  • David
    David
    2010-09-10

    It looks like the makefile explicitly requires 1394 instead of V4L:
    ifeq ($(USE_LIBDC1394_V2), 1)
    TARGET_ = $(TARGET)
    else
    TARGET_ = errormessage
    endif

    Thinking that the makefile might just not have been updated to use V4L, I tried
    hacking it to allow V4L or 1394.  But then it wouldn't compile.  So then I tried
    hacking the .cpp file to use V4L capture instead of 1394.  I got that to compile,
    but it eventually died with a fatal failed ioctl call trying to set the depth and mode.
    Is this a futile effort trying to get this USB camera working IVT?  I'm willing to
    work on it, but I'd need a lot of hand holding.

    Thanks,

             Dave

     
  • Pedram Azad
    Pedram Azad
    2010-09-10

    Hi Dave,

    sorry for the late answer, I totally forgot.

    Unfortunately, CV4LCapture is far away from being mature currently, it is just a very very basic implementation.

    Unless you want to look into it yourself and improve the code - which I would appreciate - you can use the class COpenCVCapture, which should work fine with your USB camera. You have to set USE_OPENCV = 1 and USE_OPENCV_HIGHGHUI = 1, then hack into the main.cpp of CaptureApp to use COpenCVCapture. As nIndex parameter of the constructor, try -1, which should open the first available image device. You can also try a 0 or 1 or something, I'm not sure.

    Hope that helps!

    Pedram

     
  • David
    David
    2010-09-12

    Hi Pedram,

    Thanks for the response.  I did get captureapp working using opencv.  Below is a patch file
    that got it to compile and run for me using your directions.  It crashes in a destructor on exit
    for me, but that's no big deal.  By the way, I noticed captureapp main.cpp has a mixture of
    dos and unix end of lines.

    I might be able to help out with CV4LCapture in a few months, but I have basically no
    experience with v4l or image processing so I might be more of a bother than a helper.

    diff -ur IVT.orig/examples/CaptureApp/main.cpp IVT/examples/CaptureApp/main.cpp
    -- IVT.orig/examples/CaptureApp/main.cpp 2010-07-26 10:14:14.000000000 -0700
    +++ IVT/examples/CaptureApp/main.cpp 2010-09-12 08:53:30.019733877 -0700
    @@ -48,8 +48,12 @@
    #elif defined __APPLE__

    #include "VideoCapture/QuicktimeCapture.h"

    #else

    +#ifdef OPENCVCAPTURE

    +#include "VideoCapture/OpenCVCapture.h"

    +#else

    #include "VideoCapture/Linux1394Capture2.h"

    #endif

    +#endif

    #include "Interfaces/MainWindowInterface.h"

    #include "Interfaces/MainWindowEventInterface.h"

    @@ -103,7 +107,11 @@
    #elif defined __APPLE__

    CQuicktimeCapture capture(CVideoCaptureInterface::e640x480);

    #else

    - CLinux1394Capture2 capture(-1, CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eRGB24);

    +                #ifdef OPENCVCAPTURE

    + COpenCVCapture capture(-1);

    +                #else

    +                CLinux1394Capture2 capture(-1, CVideoCaptureInterface::e640x480, CVideoCaptureInterface::eRGB24);

    +                #endif /* OPENCVCAPTURE else */

    #endif

    // open camera

    diff -ur IVT.orig/examples/CaptureApp/Makefile IVT/examples/CaptureApp/Makefile
    -- IVT.orig/examples/CaptureApp/Makefile 2010-07-26 10:14:11.000000000 -0700
    +++ IVT/examples/CaptureApp/Makefile 2010-09-11 21:33:16.000198457 -0700
    @@ -2,19 +2,22 @@

    include ../../src/Makefile.base

    -ifeq ($(shell uname), Darwin)
    +TARGET_ = errormessage
    +
    + ifeq ($(shell uname), Darwin)
    ifeq ($(USE_QUICKTIME), 1)
    TARGET_ = $(TARGET)
    - else
    - TARGET_ = errormessage
    endif
    -else
    + else
    ifeq ($(USE_LIBDC1394_V2), 1)
    TARGET_ = $(TARGET)
    - else
    - TARGET_ = errormessage
    + else ifeq ($(USE_OPENCV), 1)
    + ifeq ($(USE_OPENCV_HIGHGUI), 1)
    + TARGET_ = $(TARGET)
    + FLAGS_BASE := $(FLAGS_BASE) -DOPENCVCAPTURE
    +                endif
    endif
    -endif
    + endif

    OBJFILES = main.o
    INCPATHS = $(INCPATHS_BASE)
    @@ -37,4 +40,4 @@
    $(COMPILER) $(FLAGS) $(INCPATHS) -c main.cpp -o main.o

    errormessage:
    - @echo "For this application to compile and run a suitable video capture module must be activated. Per default, under Mac OS X the module CQuicktimeCapture is used: set USE_QUICKTIME = 1 in IVT/src/Makefile.base. Per default, under Linux the module CLinux1394Capture2 is used: set USE_LINUX1394_V2 = 1 in IVT/src/Makefile.base. After setting the appropriate variable, run 'make clean && make' in IVT/src first and then run 'make' here again."
    \ No newline at end of file
    + @echo "For this application to compile and run a suitable video capture module must be activated. Per default, under Mac OS X the module CQuicktimeCapture is used: set USE_QUICKTIME = 1 in IVT/src/Makefile.base. Per default, under Linux the module CLinux1394Capture2 is used: set USE_LINUX1394_V2 = 1 or USE_OPENCV = 1 and USE_OPENCV_HIGHGUI = 1 in IVT/src/Makefile.base. After setting the appropriate variable, run 'make clean && make' in IVT/src first and then run 'make' here again."
    \ No newline at end of file
    diff -ur IVT.orig/src/Makefile.base IVT/src/Makefile.base
    -- IVT.orig/src/Makefile.base 2010-07-26 10:14:13.000000000 -0700
    +++ IVT/src/Makefile.base 2010-09-11 21:33:30.335042229 -0700
    @@ -9,8 +9,8 @@
    # Flags for turning on/off support for integrated libraries
    # Note: Flags for GUI support can be found within the following if-statement
    USE_OPENGL = 0
    -USE_OPENCV = 0
    -USE_OPENCV_HIGHGUI = 0
    +USE_OPENCV = 1
    +USE_OPENCV_HIGHGUI = 1
    # Note: If USE_OPEN_INVENTOR = 1 is set, also either USE_QT3 = 1 or USE_QT4 = 1 (for SoQt) must be set in the following if-statement
    USE_OPEN_INVENTOR = 0