romankh3 / image-comparison

Published on Maven Central Java Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. Some parts of the image can be excluded from the comparison. Can be used for automation QA tests.
https://t.me/romankh3
Apache License 2.0
337 stars 105 forks source link

[BUG] Ignored area was not actually ignored #98

Closed mrgoroua closed 5 years ago

mrgoroua commented 5 years ago

Ignored area was set at rectangle List but at the result image selected area was not excluded from comparison see image

`@Test public void testNotEquals() throws IOException { File resultDestination = new File( "C:\!automation\git\ehopperDevUI\helperfiles\receipts\resultImage.png");

    File ExpectedCash = new File("C:\\!automation\\git\\ehopperDevUI\\helperfiles\\receipts\\ExpectedCash.png");
    File ActualCash = new File("C:\\!automation\\git\\ehopperDevUI\\helperfiles\\receipts\\ActualCash.png");        

    //given
    BufferedImage image1 = readImageFromFile(ExpectedCash);
    BufferedImage image2 = readImageFromFile(ActualCash);
    List<Rectangle> excludedAreas = new ArrayList<>();

    excludedAreas.add(new Rectangle(80, 388, 900, 514));
    excludedAreas.add(new Rectangle(410, 514, 900, 565));
    excludedAreas.add(new Rectangle(410, 636, 900, 754));

    ImageComparison imageComparison = new ImageComparison(image1, image2);
    imageComparison.setExcludedAreas(excludedAreas);

    //when
    ComparisonResult result = imageComparison.compareImages();

    //And Result Image
    BufferedImage resultImage = result.getResult();

    //Image can be saved after comparison, using ImageComparisonUtil.
    ImageComparisonUtil.saveImage(resultDestination, resultImage);

    //then
    assertEquals(result.getComparisonState(), MATCH);

}`
romankh3 commented 5 years ago

@mrgoroua, please, provide image1 and image2 as files to reproduce it. You can share it here, in issue or comments.

mrgoroua commented 5 years ago

ActualCash

////////////////////////// ExpectedCash

mrgoroua commented 5 years ago

@mrgoroua, please, provide image1 and image2 as files to reproduce it. You can share it here, in issue or comments.

@romankh3 was it helpful?

romankh3 commented 5 years ago

@mrgoroua I'm working on it.

mrgoroua commented 5 years ago

Fixed