This is a discussion on video4linux within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Hi, I'm trying to use video4linux for grabbing an image with a webcam and process it to determine 3 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I'm trying to use video4linux for grabbing an image with a webcam and process it to determine 3 colors, green, black and white with only green changing position. The webcam is working ok (checked it using xawtv). I found grabber code on the web, but it gives a format error on my webcam (Philips PCVC690K). Can anyone tell me in what way or where I should look to find the info needed? Thanks, Huub |
| |||
| Huub <"h.v.niekerk at hccnet.nl"> wrote: > The webcam is working ok (checked it using xawtv). I found grabber code > on the web, but it gives a format error on my webcam (Philips PCVC690K). If xawtv works OK I would start by studying the code for xawtv. regards Henrik -- The address in the header is only to prevent spam. My real address is: hc7(at)uthyres.com Examples of addresses which go to spammers: root@variousus.net info@k-soft.se info@k-software.biz root@localhost |
| |||
| On Wed, 31 Aug 2005 12:36:06 +0200, Huub <"h.v.niekerk at hccnet.nl"> wrote: >Hi, > >I'm trying to use video4linux for grabbing an image with a webcam and >process it to determine 3 colors, green, black and white with only green >changing position. The webcam is working ok (checked it using xawtv). I >found grabber code on the web, but it gives a format error on my webcam >(Philips PCVC690K). >Can anyone tell me in what way or where I should look to find the info >needed? Here is a Perl/Tk, webcam grabber using v4l. Most of it is Tk code to display the image, but the sub is in there to grab the image. Look at the code closely, the image comes in BGR and needs to be converted to RGB format. I do it by reversing the data, then "flipping" the image. There are other ways. See Imager::Transformations for a matrix method. The Imager module should be able to do the color work you want, read "perldoc Imager". #!/usr/bin/perl use warnings; use strict; use Video::Capture::V4l; use Imager; use Tk; use Tk::JPEG; use MIME::Base64; my $timestamp; my $temp = ''; sub grab_one { $temp = ''; $timestamp = scalar(localtime); $timestamp =~ tr/ /_/; $| = 1; my $grab = new Video::Capture::V4l or die "Unable to open Videodevice: $!"; # the following initializes the camera for NTSC my $channel = $grab->channel(1); #1 is composite, 0 is for tv my $tuner = $grab->tuner(0); $tuner->mode(1); $channel->norm(1); $tuner->set; $channel->set; my $frame = 0; my $fr = $grab->capture( $frame, 320, 240 ); my $count = 0; for ( 0 .. 1 ) { my $nfr = $grab->capture( 1 - $frame, 320, 240 ); $grab->sync($frame) or die "unable to sync"; unless ( $count == 0 ) { # save $fr now, as it contains the raw BGR data $temp = ''; open( JP, '>', \$temp ) or die $!; print JP "P6\n320 240\n255\n"; #header $nfr = reverse $nfr; print JP $nfr; close JP; my $img = Imager->new(); $img->read( data => $temp, type => 'pnm' ) or warn $img->errstr(); $img->flip( dir => "hv" ); $img->write( data => \$temp, type => 'jpeg' ) or warn $img->errstr; } $count++; $frame = 1 - $frame; $fr = $nfr; } } grab_one(); my $mw = MainWindow->new(); my $image = $mw->Photo( -data => encode_base64($temp) ); $mw->Label( -image => $image )->pack( -expand => 1, -fill => 'both' ); my $label = $mw->Label( -text => $timestamp )->pack( -side => 'top', -padx => 3 ); my $center = $mw->Frame->pack( -anchor => 'center' ); $center->Button( -text => 'Quit', -command => [ destroy => $mw ] ) ->pack( -side => 'left', -padx => 3 ); $center->Button( -text => 'Update', -command => \&update ) ->pack( -side => 'left', -padx => 3 ); $center->Button( -text => 'Save', -command => \&save_it ) ->pack( -side => 'left', -padx => 3 ); MainLoop; sub save_it { open( JP, "> $timestamp.jpg" ) or die $!; print JP $temp; close JP; $label->configure( -text => "$timestamp.jpg SAVED" ); $label->update; } sub update { grab_one(); $label->configure( -text => "$timestamp" ); $label->update; $image->configure( -data => encode_base64($temp) ); $image->update; $mw->update; } __END__ -- I'm not really a human, but I play one on earth. http://zentara.net/japh.html |
| |||
| > Here is a Perl/Tk, webcam grabber using v4l. Most of it is Tk code to > display the image, but the sub is in there to grab the image. Look at > the code closely, the image comes in BGR and needs to be converted to > RGB format. I do it by reversing the data, then "flipping" the image. > There are other ways. See Imager::Transformations for a matrix method. > Thank you, but I realize should have indicated I'm working in C. I also managed to get some C code, which appears to use Gtk. I wonder if this means that I can't get vision without either Tk or Gtk. |
| ||||
| Huub <"h.v.niekerk at hccnet.nl"> wrote: > I also managed to get some C code, which appears to use Gtk. I wonder if > this means that I can't get vision without either Tk or Gtk. No, xawtv doesn't need any of those. It only uses the athena widgets which are standard with X. On the other hand, gtk is a rather nice window programming api for X. regards Henrik -- The address in the header is only to prevent spam. My real address is: hc7(at)uthyres.com Examples of addresses which go to spammers: root@variousus.net info@k-soft.se info@k-software.biz root@localhost |