【问题标题】:Is there a faster way of comparing images than Image::Compare in Perl?有没有比 Perl 中的 Image::Compare 更快的比较图像的方法?
【发布时间】:2025-12-03 10:50:01
【问题描述】:

这是我目前的方法:

    #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;
    }
}

省略我所做的调整大小,如果图像相同,是否有最快的方法来做到这一点?目前每张图片大约需要 2-5 秒,大小约为 600x600。

考虑到我想测试 10 个图像的块大约 40 次,有没有最快的方法来获得结果?

【问题讨论】:

  • 您尝试过(外部)diff(Linux/Unix) 吗?比较使用Benchmark
  • 如果您要多次比较同一张图片,只需调整一次,而不是每次与另一张比较。

标签: perl image-comparison


【解决方案1】:

您可以将每个图像转换成一个标量,然后与eq 运算符进行比较,看看它们是否相同。不知道这是否是你想要的。

【讨论】:

  • 鉴于 png 具有元数据,并且使用了 resize_image 方法,eq 听起来不太可能是 op 真正想要的。 (虽然这个问题有点模糊..)
  • @Dada 我同意你的观点,但是代码通过相同的调整大小方法传递两个图像并与&Image::Compare::EXACT 进行比较,所以我认为eq 可能值得一试
最近更新 更多