socrtwo's Avatar
socrtwo 4
18 Asked
50 Answered
5 Best
0
No one has voted on this question yet :(
2 years, 10 months ago

Why do I get this PERL message Can't call method "scaleY" on an undefined value at C:/strawberry/perl +/site/lib/ Image/Seek.pm line 137?

This is a cross post from Perl Monks: 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.
download"

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 haar.db file as an empty one, then the script hangs and after a couple of minutes, it give this different 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/, which I was alluding to before. I obviously removed the .txt extension before trying it. The makedb.pl script is from the Japanese site where the script comes from: http://www.drk7.jp/MT/archives/001258.html.

If I run makedb.pl I get 362 instances of the error for 2423 scanned collectible postage stamps images in my target 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? However if this is true why does the database get filled with  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". Maybe the issue is when the "landscape" scaled images get an X axis of 128 pixels and then their Y axis ends up less or much less.  Could this be?

Thanks much
Tip for best answer: M$0.00

You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.

M$

What is Your Answer?

0
0
0

Learn something new with our FREE educational apps!

Private lessons in the comfort of your own home. Get back in shape or finally pick up a guitar with our great experts guiding you the whole way!
Learn Guitar
Learn Hip Hop
Learn Pilates