Ubuntu

v4l2 image capture doesn't work

Reported by Ethan Townsend on 2009-01-26
22
This bug affects 2 people
Affects Status Importance Assigned to Milestone
opencv (Ubuntu)
Undecided
Unassigned

Bug Description

Binary package hint: libcv-dev

using libcv-dev and libcv1 version 1.0.0-6.1 on kubuntu 8.10 amd64.

trying to initialize v4l2 via the demo programs (in c or python) fails with "Could not initialize capturing..." for the c programs or
"Error opening capture device" for python programs. The demo programs that did not involve webcam capture work as expected. /dev/video0 exists and works with cheese, skype, etc. I tried 2 webcams, one was a logitech with the following output from v4l-info

>### v4l2 device info [/dev/video0] ###
>general info
> VIDIOC_QUERYCAP
> driver : "zc3xx"
> card : "USB Camera (046d:08d7)"
> bus_info : "0000:00:02.0"
> version : 2.2.0
> capabilities : 0x5000001 [VIDEO_CAPTURE,READWRITE,STREAMING]

and dmesg output
>[21413.628051] usb 1-7: new full speed USB device using ohci_hcd and address 8
>[21413.833749] usb 1-7: configuration #1 chosen from 1 choice
>[21413.837178] gspca: probing 046d:08d7
>[21415.711809] zc3xx: probe 2wr ov vga 0x0000
>[21415.783806] zc3xx: probe sensor -> 11
>[21415.783819] zc3xx: Find Sensor HV7131R(c)
>[21415.805489] gspca: probe ok
>[21415.807305] gspca: probing 046d:08d7

and one creative labs webcam with this output:

>### v4l2 device info [/dev/video0] ###
>general info
> VIDIOC_QUERYCAP
> driver : "zc3xx"
> card : "USB Camera (041e:401c)"
> bus_info : "0000:00:02.0"
> version : 2.2.0
> capabilities : 0x5000001 [VIDEO_CAPTURE,READWRITE,STREAMING]

Both produced identical results with opencv.

I also tried running this python script:

>import pygame
>import Image
>from pygame.locals import *
>import sys
>
>import opencv
>#this is important for capturing/displaying images
>from opencv import highgui
>
>camera = highgui.cvCreateCameraCapture(0)
>def get_image():
> im = highgui.cvQueryFrame(camera)
> # Add the line below if you need it (Ubuntu 8.04+)
> im = opencv.cvGetMat(im)
> #convert Ipl image to PIL image
> return opencv.adaptors.Ipl2PIL(im)
>
>fps = 30.0
>pygame.init()
>window = pygame.display.set_mode((640,480))
>pygame.display.set_caption("WebCam Demo")
>screen = pygame.display.get_surface()
>
>while True:
> events = pygame.event.get()
> for event in events:
> if event.type == QUIT or event.type == KEYDOWN:
> sys.exit(0)
> im = get_image()
> pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)
> screen.blit(pg_img, (0,0))
> pygame.display.flip()
> pygame.time.delay(int(1000 * 1.0/fps))

This script fails with the following output:

>Traceback (most recent call last):
> File "test.py", line 29, in <module>
> im = get_image()
> File "test.py", line 14, in get_image
> im = opencv.cvGetMat(im)
> File "/var/lib/python-support/python2.5/opencv/cv.py", line 3826, in cvGetMat
> return _cv.cvGetMat(*args)
>RuntimeError: openCV Error:
> Status=Null pointer
> function name=cvGetMat
> error message=NULL array pointer is passed
> file_name=cxarray.cpp
> line=2780

I am new with v4l2 and opencv, I apologize if this bug should be filed under the zc3xx/gspca drivers, I have no way to test other webcam modules.

JeDi (jean-daniel-michaud) wrote :

Got the same here. Can't get a capture object from openCV, c++ or python.

v4l-info output:

### v4l2 device info [/dev/video0] ###
general info
    VIDIOC_QUERYCAP
        driver : "zc3xx"
        card : "USB Camera (046d:08da)"
        bus_info : "0000:00:1a.1"
        version : 2.2.0
        capabilities : 0x5000001 [VIDEO_CAPTURE,READWRITE,STREAMING]

standards

inputs
    VIDIOC_ENUMINPUT(0)
        index : 0
        name : "zc3xx"
        type : CAMERA
        audioset : 0
        tuner : 0
        std : 0x0 []
        status : 0x0 []

video capture
    VIDIOC_ENUM_FMT(0,VIDEO_CAPTURE)
        index : 0
        type : VIDEO_CAPTURE
        flags : 1
        description : "JPEG"
        pixelformat : 0x4745504a [JPEG]
    VIDIOC_G_FMT(VIDEO_CAPTURE)
        type : VIDEO_CAPTURE
        fmt.pix.width : 640
        fmt.pix.height : 480
        fmt.pix.pixelformat : 0x4745504a [JPEG]
        fmt.pix.field : NONE
        fmt.pix.bytesperline : 640
        fmt.pix.sizeimage : 115790
        fmt.pix.colorspace : JPEG
        fmt.pix.priv : 0

dmesg:

[ 2850.920016] usb 2-2: new full speed USB device using uhci_hcd and address 5
[ 2851.107640] usb 2-2: configuration #1 chosen from 1 choice
[ 2851.110485] gspca: probing 046d:08da
[ 2852.731236] zc3xx: probe 2wr ov vga 0x0000
[ 2852.775233] zc3xx: probe sensor -> 11
[ 2852.775240] zc3xx: Find Sensor HV7131R(c)
[ 2852.781350] gspca: probe ok
[ 2852.781404] gspca: probing 046d:08da
[ 2922.931570] zc3xx: probe 2wr ov vga 0x0000
[ 2995.611915] zc3xx: probe 2wr ov vga 0x0000

Neil Cavan (neilcavan) wrote :

I am having the same problem.

/dev/video0 exists and works fine in Cheese.

cvCreateCameraCapture(0) and cvCreateCameraCapture(200) both fail to return a Capture structure.

Does anyone have a workaround? Not having access to video devices make OpenCV fairly useless...

Did you try to run the program with "LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so" for v4l1 compatibility? Also try to use cvCreateCameraCaputer(-1).

Blu (blutack) wrote :

Neither of those fixes work (although the LD_PRELOAD works with HornetsEye, another computer vision framework).
I can't compile the SVN version of OpenCV due to an error in the SWIG bindings. Does anyone have a patch/fix/workaround at all?

DougL (dlarue) wrote :

This is what worked for me running Kubuntu 9.10

export LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so

The LD_PRELOAD workaround did not work (around) for me.

# I was able to get it working by compiling the latest OpenCV 2.2 manually.
# Of course, it would be much nicer if the deb worked.

#
# Mostly from: http://opencv.willowgarage.com/wiki/InstallGuide
#
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev python-dev

# Download the latest version, then:

tar -xvf OpenCV-2.2.0.tar.bz2
cd OpenCV-2.2.0/
cmake .

make

# Copy the file "cv.so" to any local dir your .py script is in to avoid path questions.

# To install system-wide:
#sudo make install

Note for those wanting to compile it manually: Install V4l support to get better camera capture support. (Without this I was forced to 640x480.)

sudo apt-get install libv4l-dev

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers