Video::Capture undefined value

J

josvanr

Hello

I'm trying to get to work the examples from themodule
Video-Capture-V4l-0.901
(debian package libvideo-capture-v4l-perl v 0.901-1)
All the supplied examples seem to be suffering from the same
problem:

stumpernickel:/usr/share/doc/libvideo-capture-v4l-perl/examples# ./grab
Device: name Logitech QuickCam Pro 4000, type capture, channels 1,
audios 1, sizes 160x120-640x480
Channel 0: name Webcam, tuners 0, flags, type camera, norm 0
Picture Settings: brightness 32256, hue 65535, colour 40616, contrast
64512, whiteness 49152, depth 24, palette 15
Can't call method "mode" on an undefined value at ./grab line 103.


Has anyone encountered (and /or solved) the same problem?

Jos
 
J

josvanr

Line 103 defines the tuner (i.e. TV channel tuner), and I'm
probably right, in that your camera has no tuner.... it's just
a plain camera.


yes that seems to work, no error msg now. The camera led flashes
when I run the script. Now I only need to figure out how to save a
frame..

Jos
 
Z

zentara

yes that seems to work, no error msg now. The camera led flashes
when I run the script. Now I only need to figure out how to save a
frame..
Jos

Grabbing is kind of tricky, the thing to watch for is sometimes the
camera sends it out bgr instead of rgb, or upside down ,etc,
Also, you seem to need to grab 2, to get 1 image? I havn't
figured out why, I just know it works.
Finally, if you get a blue image, it means the camera was not
"initialized" properly. The "v4lctl" program is good for
this, you can run it thru system, or IPC.
I have an example of running it thru IPC at
http://perlmonks.org?node_id=486896


Heres a grabber:

#!/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(0);
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__
 

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top