in reply to Re: capturing raw video with v4l
in thread capturing raw video with v4l

Well thanks, you got me on the right track. As usual, I make advances by making "educated guesses". :-) I noticed that the output of videodog's raw frame, and a pnm frame was the same except for a header. So I added a header to each frame and renamed it pnm. Now another problem arises....the raw data is actually BGR not RGB ( I thought it was a typo, but it's not). So now I need to figure out how to quickly process the frame to change it from BGR to RGB.

New code which outputs blue-tinted pnm's.

#!/usr/bin/perl use Video::Capture::V4l; $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(1..5) { my $nfr = $grab->capture (1-$frame, 320, 240); $grab->sync($frame) or die "unable to sync"; # save $fr now, as it contains the raw BGR data open (JP,">z$count.pnm") or die $!; print JP "P6\n320 240\n255\n"; #header print JP $nfr; close JP; print "."; $count++; $frame = 1-$frame; $fr = $nfr; }

Replies are listed 'Best First'.
Re: Re: Re: capturing raw video with v4l
by BobbyVector (Monk) on Feb 18, 2004 at 16:08 UTC
    Don't know how quick it is, but here's my stab at converting from BGR to RGB.
    sub convert_to_rgb { my $bgr = shift; my $bgrLen = length($bgr); #Unpacking the BGR data gives use easy access to individual bytes. my @bgrArray = unpack("C$bgrLen",$bgr); my @rgbArray; my $ct=0; while ($ct < $bgrLen) { $rgbArray[$ct] = $bgrArray[$ct+2]; $rgbArray[$ct+1] = $bgrArray[$ct+1]; $rgbArray[$ct+2] = $bgrArray[$ct]; $ct+=3; } #Pack the data to match the input format. my $rgb = pack("C$bgrLen",@rgbArray); return $rgb; }
    Pass the code $nfr and the returned value can be written to file in place of $nfr.
      Hi, that's a nice pure perl snippet, however it still would be faster to let Imager do it, since it uses xs and C to do the same thing, and faster too for big image files.

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