0

I have two images which I want to compare with the ImageMagick Java wrapper 'im4java'. As far I have this piece of code:

boolean compare (String picture1, String picture2) {
    boolean pdfsEqual;
    IMOperation imOperation = new IMOperation();
    imOperation.metric("ae");
    imOperation.addImage();
    imOperation.addImage();
    imOperation.addImage();
    CompareCmd compare = new CompareCmd();
    ArrayListOutputConsumer outputConsumer = new ArrayListOutputConsumer();
    compare.setOutputConsumer(outputConsumer);
    try{
        compare.run(imOperation, pathSample, pathResult, "null:");
        pdfsEqual = true;
    } catch (Exception e){
        pdfsEqual = false;
        ArrayList<String> stringArrayList = outputConsumer.getOutput();
        System.out.println(stringArrayList);
    }
    return pdfsEqual;
}

But the stringArrayList is empty. Reading im4java documentation I found that actually the OutputConsumer stores the output in an array list but as already said there is nothing. Also, imOperation.metric("ae") counts the pixels that are different between the two images and prints it to the console if the call has been done from command prompt itself. I can't figure out how I can get this number of diff pixels in my java code using the OutputConsumer.

fabian
  • 80,457
  • 12
  • 86
  • 114
Arthur Eirich
  • 3,368
  • 9
  • 31
  • 63
  • I can't really read java, but have some experience of ImageMagick, but... have you actually added any images to compare - the parameters to `addImage()` look very empty to this C programmer. – Mark Setchell Oct 23 '15 at 07:46
  • `addImage()` is just a placeholder for adding an image. The actually adding is done by `compare.run(IMOperation, Object ...objects)` where I give the paths to the images as second and third argument. – Arthur Eirich Oct 23 '15 at 08:06
  • There may be a really simple solution to this, but I don't know Java and am just trying to help you get going, ok? Another idea for a workaround just to get you going is to use the `convert` program, rather than the `compare` program within ImageMagick. At the commandline, you can run this command instead of your`compare` command and get the same result... `convert -metric ae image1.png image2.png -compare -format "%[distortion]" info:` – Mark Setchell Oct 23 '15 at 08:17
  • @MarkSetchell Sure, I am not against any hints=) Actually I could get the desired behavior on the command prompt and I get the counter for different pixels as output in the console but the problem is that I actually need to read this counter in java. Thank you anyway! – Arthur Eirich Oct 23 '15 at 08:20

1 Answers1

0

Try it with

ArrayListErrorConsumer and setErrorConsumer

instead of

ArrayListOutputConsumer and setOutputConsumer

I don't know why it appears in on the wrong consumer. Maybe it is a bug.