0

This is my current method:

    #Object to compare images
    my $cmp = Image::Compare->new();

    # Resize images
    my ($image_1_resized_file, $image_2_resized_file) = resize_images($image_1_file, $image_2_file);

    # Configure comparison
    $cmp->set_image1(
        img  => $image_1_resized_file,
        type => 'png',
    );
    $cmp->set_image2(
        img  => $image_2_resized_file,
        type => 'png',
    ); 


    $cmp->set_method(
       method => &Image::Compare::EXACT,
    );

    # Compare
    if ($cmp->compare()) {
        print "[DEBUG] Images are the same\n"  if ($self->{_debug_prints} eq 1);

        # Remove temp files
        unlink $image_1_resized_file;
        unlink $image_2_resized_file;

        return 1;
    }
    else {
        print "[ERROR] Images are not the same\n";

        #Remove temp files
        unlink $image_1_resized_file;
        unlink $image_2_resized_file;

        return 0;
    }
}

Ommiting the resizing that I do, If the images are the same, is there a fastest way to do this?. Currently is taking around 2-5 seconds per image, with an aproximated size of 600x600.

Considering that I want to test blocks of 10 images around 40 times, is there a fastest way to get the results?

nck
  • 1,673
  • 16
  • 40
  • Did you try the (external) `diff`(Linux/Unix) ? Compare using [Benchmark](https://perldoc.perl.org/Benchmark.html) – zdim Aug 15 '19 at 17:12
  • If you're comparing the same image multiple times, only resize it once instead of every time it's compared to another. – Shawn Aug 15 '19 at 21:23

1 Answers1

0

You could slurp each image into a scalar and then compare with the eq operator to see if they are identical. Not sure if this is what you want though.

JGNI
  • 3,933
  • 11
  • 21
  • Given the fact that png have metadata, and that a method `resize_image` is used, it sounds unlikely that `eq` is actually what the op wants. (the question is a bit vague though..) – Dada Aug 20 '19 at 13:26
  • @Dada I agree with your sentiment, however the code is passing both images through the same resize method and comparing with `&Image::Compare::EXACT`, so I thought `eq` might be worth a try – JGNI Aug 20 '19 at 14:09