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
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
Separate topics with commas, or by pressing return. Use the delete or backspace key to edit or remove existing topics.
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$1 Answer
It appears to me that perl isn't allowing you to call a function on an object with a function called on it. I know you said that removing the ->scaleY(pixels => 128) causing the same type of error on line 129, but I think that's another problem. You have y => $y, which looks like you are assigning y the value of y, unless I am not remembering perl as well as I wish. I suggest you remove the ->scaleY(pixels => 128) and do it in a separate statement, and then change line 129 to get rid of the error on that line.
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$
OK. It looks like the Imager module is the problem. It does not detect the libraries for JPEG or PNG if you install version 0.67 manually in Windows with my Strawberry PERL which is what I'm doing. Does anybody know where Imager is looking for the libraries for the various extensions? I'l tip $2 for the right answer :-).
It turned out the Perl Module worked fine. I changed the images to bmps changed the upload script to accept bmps and it worked. Still mysterious...I was able to install the jpeg libraries, but this did not matter....