You are not logged in.
Pages: 1
hello,
So I am coding a motion detector using my webcam and the opencv libraries. The webcam shows up as
Bus 002 Device 002: ID 05a9:a511 OmniVision Technologies, Inc. OV511+ Webcam
so I believe I am to use v4l.
Now, the camera works with mplayer, however I feel it is not using v4l. My mplayer command and output is:
# mplayer tv:// -vo x11 -tv fps=15:driver=v4l:width=352:height=288
MPlayer SVN-r29411-4.4.0 (C) 2000-2009 MPlayer Team
137 audio & 299 video codecs
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing tv://.
TV file format detected.
Selected driver: v4l
name: Video 4 Linux input
author: Alex Beregszaszi
comment: under development
Selected device: OV511+ USB Camera
Capabilites: capture subcapture
Device type: 513
Supported sizes: 64x48 => 352x288
Inputs: 1
0: Camera: (tuner:0, norm:pal)
Using input 'Camera'
tv.c: norm_from_string(pal): Bogus norm parameter, setting default.
Unknown norm!
Error: Cannot set norm!
Selected input hasn't got a tuner!
==========================================================================
Opening video decoder: [raw] RAW Uncompressed Video
VDec: vo config request - 352 x 288 (preferred colorspace: Planar YV12)
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is undefined - no prescaling applied.
VO: [x11] 352x288 => 352x288 Planar YV12
[swscaler @ 0x90afa70]using unscaled yuv420p -> rgb32 special converter
Selected video codec: [rawyv12] vfm: raw (RAW YV12)
==========================================================================
Audio: no sound
Starting playback...
V:-9223372036854.8 241/241 ??% ??% ??,?% 0 0
MPlayer interrupted by signal 2 in module: video_read_frame
MJP: returning! 242/242 ??% ??% ??,?% 0 0
Exiting... (Quit)
However when I am running my program all I get is a white screen. It finds the correct input however no data is coming from it. Here is the code that I am testing with:
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
int main( int argc, char **argv )
{
CvCapture *capture = 0;
IplImage *frame = 0;
int key = 0;
/* initialize camera */
capture = cvCaptureFromCAM( 0 );
/* always check */
if ( !capture ) {
fprintf( stderr, "Cannot open initialize webcam!\n" );
return 1;
}
/* create a window for the video */
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
while( key != 'q' ) {
/* get a frame */
frame = cvQueryFrame( capture );
/* always check */
if( !frame ) break;
/* display current frame */
cvShowImage( "result", frame );
/* exit if user press 'q' */
key = cvWaitKey( 1 );
}
/* free memory */
cvDestroyWindow( "result" );
cvReleaseCapture( &capture );
return 0;
}
I have heard this might have something to do with ffmpeg and the -enable-shared option. My ffmpeg seems to have it enabled:
# ffmpeg
FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --prefix=/usr --enable-gpl --enable-libmp3lame --enable-libvorbis --enable-libfaac --enable-libfaad --enable-libxvid --enable-libx264 --enable-libtheora --enable-postproc --enable-shared --enable-pthreads --enable-x11grab --enable-swscale
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Apr 20 2009 01:37:42, gcc: 4.3.3
At least one output file must be specified
My lsmod:
# lsmod
Module Size Used by
ipv6 277876 17
ext2 69036 1
snd_seq_dummy 2696 0
snd_seq_oss 31168 0
snd_seq_midi_event 7012 1 snd_seq_oss
snd_seq 53744 5 snd_seq_dummy,snd_seq_oss,snd_seq_midi_event
snd_pcm_oss 40352 1
snd_mixer_oss 17540 1 snd_pcm_oss
ov511 73040 0
videodev 36544 1 ov511
v4l1_compat 15688 1 videodev
arc4 1732 2
ecb 2788 2
snd_cs46xx 84512 1
gameport 11280 2 snd_cs46xx
snd_rawmidi 21856 1 snd_cs46xx
snd_seq_device 6768 4 snd_seq_dummy,snd_seq_oss,snd_seq,snd_rawmidi
snd_ac97_codec 106088 1 snd_cs46xx
ac97_bus 1540 1 snd_ac97_codec
snd_pcm 73512 3 snd_pcm_oss,snd_cs46xx,snd_ac97_codec
snd_timer 21100 2 snd_seq,snd_pcm
snd 58436 10 snd_seq_oss,snd_seq,snd_pcm_oss,snd_mixer_oss,snd_cs46xx,snd_rawmidi,snd_seq_device,snd_ac97_codec,snd_pcm,snd_timer
soundcore 6784 2 snd
snd_page_alloc 8876 2 snd_cs46xx,snd_pcm
ath5k 121704 0
mac80211 182976 1 ath5k
led_class 3976 1 ath5k
cfg80211 67364 2 ath5k,mac80211
via_rhine 22764 0
mii 4804 1 via_rhine
ppdev 7656 0
fan 4392 0
psmouse 59644 0
uhci_hcd 23540 0
i2c_i801 9656 0
i2c_core 22776 1 i2c_i801
parport_pc 36964 1
lp 9700 0
parport 34380 3 ppdev,parport_pc,lp
button 5556 0
iTCO_wdt 10952 0
iTCO_vendor_support 3080 1 iTCO_wdt
processor 35864 0
shpchp 34328 0
pci_hotplug 28964 1 shpchp
thermal 13888 0
ehci_hcd 36112 0
battery 10984 0
serio_raw 5704 0
usbcore 150160 4 ov511,uhci_hcd,ehci_hcd
intel_agp 27484 1
agpgart 32756 1 intel_agp
sg 27928 0
ac 4360 0
evdev 10176 8
rtc_cmos 11212 0
rtc_core 18048 1 rtc_cmos
rtc_lib 2500 1 rtc_core
ext4 237988 10
mbcache 7080 2 ext2,ext4
jbd2 57756 1 ext4
crc16 1636 1 ext4
dm_mod 60836 24
sr_mod 16612 0
sd_mod 27328 8
cdrom 36032 1 sr_mod
ata_generic 4680 0
ata_piix 23080 6
pata_acpi 4228 0
floppy 55780 0
libata 168044 3 ata_generic,ata_piix,pata_acpi
scsi_mod 110708 4 sg,sr_mod,sd_mod,libata
I am using the newest version of opencv which I found on AUR.
I doubt it has anything to do with it but I am running xfce as my de.
I can't think of anything else that would be helpful, however just let me know and I can add it.
So if someone knows why I can only get a white image with the code and I can get the full video from mplayer I would be happy. Also, if anyone knows a solution I would be even happier!
Thanks alot,
Brian
Offline
I have a few updates which might help figure out the problem.
Since I upgraded to the new svn, with the white screen I get these errors:
# ./webcam
libv4l2: error getting capabilities: Invalid argument
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT
libv4l2: error getting capabilities: Invalid argument
(<unknown>:7720): GStreamer-CRITICAL **:
Trying to dispose element appsink1, but it is not in the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
(<unknown>:7720): GStreamer-CRITICAL **:
Trying to dispose element ffmpegcsp1, but it is not in the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
(<unknown>:7720): GStreamer-CRITICAL **:
Trying to dispose element fakesink, but it is not in the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
(<unknown>:7720): GStreamer-CRITICAL **:
Trying to dispose element typefind, but it is not in the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
(<unknown>:7720): GStreamer-CRITICAL **:
Trying to dispose element decodebin1, but it is not in the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
(<unknown>:7720): GStreamer-CRITICAL **:
Trying to dispose element capsfilter0, but it is not in the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
linking pad video/x-raw-yuv
Also with dmesg I found I got:
ov511: Invalid channel (1)
Hope this helps.
Thanks again.
Offline
Looking farther, I have installed the v4l from the stable packages. I no longer get the errors from the webcam program. However it appears that nothing has changed with the video stream. I have tried using python scripts to do the same thing which works fine and I see the output of the camera. Though, I am not able to use python for this project. I have more information about v4l
# v4l-conf
v4l-conf: using X11 display :0.0
dga: version 2.0
mode: 1024x768, depth=24, bpp=32, bpl=4096, base=0xf0000000
/dev/video0 [v4l2]: ioctl VIDIOC_QUERYCAP: Invalid argument
/dev/video0 [v4l]: no overlay support
vl4-info
# v4l-info
### video4linux device info [/dev/video0] ###
general info
VIDIOCGCAP
name : "OV511+ USB Camera"
type : 0x201 [CAPTURE,SUBCAPTURE]
channels : 1
audios : 0
maxwidth : 352
maxheight : 288
minwidth : 64
minheight : 48
channels
VIDIOCGCHAN(0)
channel : 0
name : "Camera"
tuners : 0
flags : 0x0 []
type : CAMERA
norm : 0
tuner
ioctl VIDIOCGTUNER: Invalid argument
audio
ioctl VIDIOCGAUDIO: Invalid argument
picture
VIDIOCGPICT
brightness : 25088
hue : 65280
colour : 24576
contrast : 32512
whiteness : 26880
depth : 12
palette : YUV420
buffer
VIDIOCGFBUF
base : (nil)
height : 0
width : 0
depth : 0
bytesperline : 0
window
VIDIOCGWIN
x : 0
y : 0
width : 352
height : 288
chromakey : 0
flags : 30
So, if anyone has any idea on why it wont work with c/c++ correctly please let me know. I am struggling with this and the reason escapes me. If python scripts work, I would assume the c code would work too. They are essentually using the same library, from what I can tell.
Thanks
Brian
Offline
Pages: 1