jMagick - image comparision

拥有回忆 提交于 2019-12-04 12:42:19
boolean compareSuccess = compareImages("src/main/1.jpg","src/test/resources/bag_frame2.gif", "src/test/resources/ex.gif");
 //(input1,input2,outputfile)
//(boolean=true if same image...false if changes in image)
compareImages (String data,String data1, String diff) {

  CompareCmd compare = new CompareCmd();

  // For metric-output
  compare.setErrorConsumer(StandardStream.STDERR);
  IMOperation cmpOp = new IMOperation();
  // Set the compare metric
  cmpOp.metric("mae");

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

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

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

  try {
    // Do the compare
    compare.run(cmpOp);
    return true;
  }
  catch (Exception ex) {
    return false;
  }
}

Try this.And dont forget to import im4java or maven

If you are fine with doing system calls, you can use pdiff. http://pdiff.sourceforge.net/ The tool has been written to compare rendering engines and will output the differences between two files to a new file. It does not seem to have Java bindings though.

In this link you can find an example of image comparison Class using jMagick. They used compare command line function to handle image comparison.

Code snippet:

String[] cmd = new String[] {"compare","-metric","MSE",file1,file2,"tempcompareImage.jpg"};

https://github.com/techblue/jmagick/blob/master/test/magicktest/MagickTesttools.java

Also, you can find the details of compare function here: http://www.imagemagick.org/Usage/compare/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!