Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Problem with Image::Compare module.

by balajinagaraju (Sexton)
on May 03, 2012 at 08:15 UTC ( [id://968669]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I am using the Image::Compare module to compare two images and here is my code

sub CompareImage{ print " CompareImage function called"; my @args = @{$_[0]}; print "Arguments:".@args[0]; print "Arguments:".@args[1]; my($cmp) = Image::Compare->new(); $cmp->set_image1( img => '@args[0]', ); $cmp->set_image2( img => '@args[1]', ); $cmp->set_method( method => &Image::Compare::THRESHOLD, args => 25, ); if ($cmp->compare()) { print 'The images are the same, within the threshold'; return 'PASS'; } else { print 'The images differ beyond the threshold'; return 'FAIL'; } }

I am triggering this function from a different file and i am passing an array reference which holds the images to be compared(absolute path to the image files). I am accessing the images using the indexes and itseems to be failing during the comparison, when i print the content of the array i am getting the correct values but if i use it a comparison it fails, however if i hardcode the path values the function works fine. I am getting the below error with the above usage.

CompareImage function called Arguments:D:\\img1.jpg Arguments:D:\\img2.jpg Unable to read image data from file '$args[0]': 'Could not open $args[0]: No such file or directory' at C:/strawberry/perl/site/lib/Image/Compare.pm line 162. Can anyone help me resolve the issue.

Replies are listed 'Best First'.
Re: Problem with Image::Compare module.
by Anonymous Monk on May 03, 2012 at 08:18 UTC

    Its because single quotes do not interpolate while double quotes do interpolate. perlintro and Modern Perl explain interpolation.

Re: Problem with Image::Compare module.
by Anonymous Monk on May 03, 2012 at 08:28 UTC
    Do not use any quotes at all for single variables. Write:
    img => $args[0],
      Thanks for your reply , it works fine now.

Log In?
Username:
Password:

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

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

    No recent polls found