Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Can't call method "scaleY" on an undefined value at C:/strawberry/perl/site/lib/ Image/Seek.pm line 137.

by socrtwo (Sexton)
on Jul 28, 2009 at 03:16 UTC ( [id://783729]=perlquestion: print w/replies, xml ) Need Help??

socrtwo has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am getting the error in the title when calling the Image::Seek module from my script. My script is basically a rehash of the module's suggested code.

Here's the error again:

Can't call method "scaleY" on an undefined value at C:/strawberry/perl +/site/lib/ Image/Seek.pm line 137.
Here's my code:
#!/usr/local/bin/perl use Imager; use Image::Seek qw(loaddb add_image query_id savedb); loaddb("haar.db"); my $img = Imager->new(); $img->open(file => "photo-216.jpg"); add_image($img, 216); savedb("haar.db"); my @results = query_id(216); # What looks like this photo?
Here's the section of the Image::Seek module causing the issue:
sub add_image_imager { my ($img, $id) = @_; my ($reds, $blues, $greens); require Imager; my $thumb = $img->scaleX(pixels => 128)->scaleY(pixels => 128); for my $y (0..127) { my @cols = $thumb->getscanline(y => $y); for (@cols) { my ($r, $g, $b) = $_->rgba; $reds .= chr($r); $blues .= chr($b); $greens .= chr($g); } } addImage($id, $reds, $greens, $blues); }

Line 137 is:

my $thumb = $img->scaleX(pixels => 128)->scaleY(pixels => 128);

If I remove

->scaleY(pixels => 128)

then line 129:

my @cols = $thumb->getscanline(y => $y);

gives me essentially the same error.

At this point I'm just trying to add one image to the database. There is an image in the directory where I'm running the script to add the image, named "photo-216.jpg". If I change the name to "photo-1.jpg" or "photo-0.jpg" and change the corresponding "add_image" and "query_id" to respectively 1 or 0, it's the same result.

I do have a database that is 385 kb big that comes from running makedb.pl below, but it is filled with null characters. I renamed this "haar.db". This is the database that gives me the error. If I recreate the file as an empty one, then the script hangs and after a couple of minutes, it give this message: "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information." If there is no "haar.db" the file still gives me the error in this post's title and unlike running makedb.pl, gives me no database named "haar.db".

By the way I get multiple examples of this post's title error also when trying to run this database filling script: http://www.drk7.jp/pub/imgseek/t/makedb.pl.txt. I obviously removed the .txt extension before trying it. The makedb.pl script is from this Japanese site: from this site: http://www.drk7.jp/MT/archives/001258.html.

Thanks much

If I run makedb.pl I get 362 instances of the error for 2423 stamps images in the directory. The 2423 stamps is the number after removing the "small" thumbnail versions which I though might be causing the issue. Could it be, some of the images are less than 128 pixels and that is the issue? But why doesn't the database get filled with other than the null characters?...Unless they are not really null even though Notebook++ says they are. Also note my images are of stamps which are only sometimes perfect squares. Sometimes they are "landscape" sometimes "portrait".
  • Comment on Can't call method "scaleY" on an undefined value at C:/strawberry/perl/site/lib/ Image/Seek.pm line 137.
  • Select or Download Code

Replies are listed 'Best First'.
Re: Can't call method "scaleY" on an undefined value at C:/strawberry/perl/site/lib/ Image/Seek.pm line 137.
by ikegami (Patriarch) on Jul 28, 2009 at 04:03 UTC
    A good thing to check would be whether open returned an error or not.
      I've been considering allowing open (or read, the official name) to be called as a class method instead, to avoid errors like this:
      my $img = Imager->open(file => $foo) or die Imager->errstr;
      It would reduce some of the useless boilerplate Imager->new
        The typical shortcut for
        my $img = Imager->new(); $img->read(...) or ...;
        is
        my $img = Imager->new(...) or ...;
        This
        my $img = Imager->new(); $img->open(file => "photo-1.jpg")or die Imager->errstr;
        Gave me this message:
        Can't locate Imager/File/JPEGReader.pm in @INC (@INC contains: C:/stra +wberry/per l/lib C:/strawberry/perl/site/lib .) at C:/strawberry/perl/site/lib/Im +ager.pm li ne 1538. ...propagated at processimage.pl line 8.
        Which I guess is progress however I don't seem to have JPEGReader.pm and cpan command line does not seem to know about it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://783729]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-19 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found