Thank You Zaxo, you answered 2 questions for the price of 1. :-) I was wondering how I could do the hex byte swap manually,
with perl, and your pack-unpack method does work fine, but it is quite slow(plus Imager can convert to jpg). I played around some more, and found that I could save a little bit of processing by reversing the BGR string(which left it RGB but upside down and flipped :-)), then use Imager to do a hv flip. The advantge to this is I didn't need to make a copy of the imager object, since an hv flip can be done in-place on the object. The code I've settled on is below.
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
my $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(file=>"z$count.jpg", type=>'jpeg')
or warn $img->errstr;
}
$count++;
$frame = 1-$frame;
$fr = $nfr;
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.