Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I don't know about windows, but this may help you with your V4l on linux. Notice, if your webcam has a tuner, you have to watch which channel you use. Your composite will be on channel(1) if your card has a tv tuner, otherwise channel(0). Also notice the need to convert from BGR to RGB.
#!/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 tuner 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; }

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Cross platform webcam-capturing? by zentara
in thread Cross platform webcam-capturing? by schweini

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2025-06-21 23:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.