#!/usr/bin/perl use warnings; use strict; use Video::Capture::V4l; use Imager; my $grab = new Video::Capture::V4l or die "Unable to open Videodevice: $!"; $|=1; 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 open (JP,">z$count.pnm") or die $!; #my $temp=''; #this fails when passing to Imager # open (JP,">",\$temp)or die $!; print JP "P6\n320 240\n255\n"; #header print JP $nfr; close JP; # convert bgr to rgb my $img = Imager->new(); $img->open(file=>"z$count.pnm", type => 'pnm') or die $img->errstr(); my $newimg = $img->copy(); $newimg = $img->convert(matrix=>[ [ 0, 0, 1 ], [ 0, 1, 0 ], [ 1, 0, 0 ] ]); $newimg->write(file=>"z$count.jpg", type=>'jpeg') or die $img->errstr; } $count++; $frame = 1-$frame; $fr = $nfr; }