Hi, I have some code which directly captures images from a bt848 camera. It works OK. In the below code, the captured image is pnm, but it is in BGR format, so I need to reopen it with the Imager module, and use it's cool matrix method to convert it to RGB. Now my question is this: How can avoid writing the file twice to disk? First V4L writes a pnm, then I have to reopen the pnm with Imager.

I tried to change the output filehandle for the v4l pnm to a scalar string(I'm using 5.8), so instead of opening a file, I opened \$temp. That goes OK, but when I try to use Imager to open \$temp, it just dies and dumps \$temp to STDERR.

So is it possible to somehow pass \$temp to Imager?

#!/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->err +str(); 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; }

update (broquaint): added <readmore> tag


In reply to Using IO::String with a module by zentara

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.