Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Use of uninitialized value $pic

by dazz (Sexton)
on Apr 24, 2017 at 09:30 UTC ( #1188746=note: print w/replies, xml ) Need Help??


in reply to Use of uninitialized value $pic

Hello I have added the statements
my $info= $snapshot->type; print ("image info : $info"); #debug
This fails as uninitialised as well. So it appears the problem is with the Image::Grab code.
Knowing that doesn't help me solve the problem.
I have pinged the camera to make sure it is reachable from my headless box.

If Image::Grab is failing, I don't know why.

Replies are listed 'Best First'.
Re^2: Use of uninitialized value $pic
by dazz (Sexton) on Apr 24, 2017 at 09:38 UTC
    SOLVED I found a typing error in the reference to the hash with the URL. The debugger/compiler didn't pick it up.
      SOLVED I found a typing error in the reference to the hash with the URL.

      And the typo was? I bet on

      - $snapshot-> url( "IPCamera{$key}"); + $snapshot-> url( "$IPCamera{$key}");

      BTW there's no need to put that into double quotes, or is there? if you had written

      $snapshot-> url( IPCamera{$key});

      the compiler would have catched that error.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Yes, because it was in double quotes, so it was a valid string. You don't need the quote though, $snapshot->url( $IPCamera{$key} ); does pretty much the same thing. One difference is that if you forget the $ outside of a string, it is not valid code anymore. The double quotes also mean that perl turns $IPCamera{$key} into a string before using it as a parameter for url(). But I'm pretty sure that your url already is a string to begin with, so stringifying it is not necessary.

      Your question garnered very few replies which is often an indication that it wasn't well constructed. In this case using a literal string instead of the hash value would not only have made it clearer for us, but you'd actually have discovered the error an hour ago before you even submitted the question. A virtue of Perl Monks that has nothing to do with the community is that well asked questions often provide their own answer. :-)

      Premature optimization is the root of all job security
        Hello Yes, it wasn't a good night for troubleshooting code. I have incorporated your suggestions and fixed the code.
        I used a hash because I have a couple of switches and args that determine which camera is being used and where the files should go.

        Moving onto my next problem. I want to call a subroutine ImageNotDark. I want to pass an Image::Magick object ($pic).
        By design, the object is not changed inside the subroutine. My problem is that I am not passing the image object correctly.
        # Convert to Image::Maggick image my $pic = Image::Magick->new(magick=>'jpg'); # create new image obj +ect $pic->BlobToImage($img); #convert the grabbed blob image to Image::Ma +gick object ## test point A #pass the $pic object to the subroutine and measure image darkness. my $test = ImageNotDark ($pic); #
        The code snippet at the start of the subroutine is as follows:
        sub ImageNotDark { # Argument is one reference to an image object. # ImageNotDark compares the image with a blank black canvas. If the c +omparison is # above the defined threshold, the image is bright enough to send (not + dark). # the return value is true if the images is bright enough. my $iutImage = Image::Magick->new; #the image tested for darkness $iutImage->Read(@_); # get the image under test (iut)
        So the debugger shows that $iutImage is not initialised. At test point A, I temporarily added code to save the $pic image to a file.
        I was able to confirm that $pic holds a valid image. So I am reasonably certain the problem is the way I call the subroutine and attempt to pass the image. Any tips would be much appreciated.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1188746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2020-10-20 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (210 votes). Check out past polls.

    Notices?