mardi 30 juin 2020

Is it possible to rework this function to ignore screenshot dimensions? If yes how?

So I am comparing two environments based on their visual appearance. I run this test on multiple "products".

Lets say I have product with ID 5500 that is on DEV and DEV2 environment. I need the best solution to compare pages between DEV and DEV2 environment based on screenshots of whole page. Right now I'm using AShot which is not working so well because it will throw exception every time the coordinates of getRGB() are not in bound which I think I cannot influence. (If you have any tips how to highlight size differences also, that would really help also)

I have also a function that calculates a percentage difference between mentioned screenshots. Right now it requires both screenshots to have same size... (f.e. Screenshot 1: 1024x1024, Screenshot 2: 1024x1024). That would be the ideal case, but the real cases are that Screenshot 1: 1024x768 and Screenshot 2: 1000x750

Right now this function calculates the percentage difference based on RGB Model. It would be nice if the size difference was taken into account also. Is it possible to include size difference to this function? Function is written like this. (Found here on Stack OverFlow.)

 public double getDifferencePercent(BufferedImage img1, BufferedImage img2) {
    int width = img1.getWidth();
    int height = img1.getHeight();
    int width2 = img2.getWidth();
    int height2 = img2.getHeight();


    long diff = 0;
    System.out.println("THIS IS DIFF BEFORE FOR LOOP: " + diff);
    try {
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                diff += pixelDiff(img1.getRGB(x, y), img2.getRGB(x, y));
            }
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        e.printStackTrace();
        System.out.println("ERROR: Screenshot dimensions are not same, thus value may be inaccurate");
    }
    System.out.println("THIS IS DIFF AFTER FOR LOOP: " + diff);

    long maxDiff = 3L * 255 * width * height;
    return 100.0 * diff / maxDiff;
}

Aucun commentaire:

Enregistrer un commentaire