繁体   English   中英

如何使用im4java比较不同大小的图像

[英]How to compare images of different sizes using im4java

我有两个图像I-1和I-2,我能够使用im4java成功比较这两个图像。 但是现在I-1和I-2具有不同的大小,因此当我尝试比较这两个图像时,不对其进行比较并给出消息

例如: org.im4java.core.CommandException:org.im4java.core.CommandException:compare.exe:图像宽度或高度不同`C:\\ Users \\ hp \\ workspace-getlinks-multipurpose \\ links_extractor / snapshots / actuals / id-dashboard .jpg” @ error / compare.c / CompareImageCommand / 990。

以下是我的代码:

      public static boolean compareImages(String exp, String cur,String output) {


    // This instance wraps the compare command
    CompareCmd compare = new CompareCmd();

    // For metric-output
    //compare.setErrorConsumer(StandardStream.STDERR);

    IMOperation cmpOp = new IMOperation();
    // Set the compare metric
    cmpOp.metric("mae");


//  cmpOp.addSubOperation(subimageSearch());

    // Add the expected image
    cmpOp.addImage(exp);

    // Add the current image
    cmpOp.addImage(cur);

    // This stores the difference
    cmpOp.addImage(output); 

    try {
        // Do the compare
        compare.run(cmpOp);

        return true;

    } catch (Exception ex) {

        System.out.println("ex: "+ex);

        return false;

    }
}

除了Pawan之外,另一个选择是使用phash度量标准:compare -metric phash image2.png image1.png cmp.png

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM