sameAs라는 메소드가 있고, 그것을 구현하는 내용을 한번 작성해봤다.


 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.awt.image.BufferedImage;
 
import com.android.chimpchat.adb.AdbBackend;
import com.android.chimpchat.core.IChimpDevice;
import com.android.chimpchat.core.IChimpImage;
 
import com.android.chimpchat.adb.AdbChimpDevice;
 
import com.android.chimpchat.core.ChimpImageBase;
 
public class MonkeyTest {
    public static void main(String[] args) {
        
        IChimpDevice device = null;
        
        try
        {
            // sdk/platform-tools has to be in PATH env variable in order to find adb
            device = new AdbBackend().waitForConnection();            
        }
        catch(java.lang.NullPointerException e)
        {
            System.out.println("Error");
            System.exit(-1);
        }
        
        // Print Device Name
        System.out.println(device.getProperty("build.model"));
 
        // Take a snapshot and save to out.png
        //device.takeSnapshot().writeToFile("out.png", "png");
        
        IChimpImage deviceImage = device.takeSnapshot();
        deviceImage.writeToFile("out_1.png""png");
        IChimpImage fileImage = ChimpImageBase.loadImageFromFile("out.png");
        fileImage.writeToFile("out_2.png""png");
        
        sameAs(fileImage,deviceImage,0.9);
        
        if(fileImage.sameAs(deviceImage, 0.75))
        {
            System.out.println("Sames");
        }
        else
        {
            System.out.println("Not");
        }
 
        device.dispose();
        
        System.exit(0);
    }
    
    public static boolean sameAs(IChimpImage other, IChimpImage sames, double percent){
        
        BufferedImage otherImage = other.getBufferedImage();
        BufferedImage samesImage = sames.getBufferedImage();
        
        //Easy size check
        if(otherImage.getWidth()!= samesImage.getWidth()){
            return false;
        }
        
        if(otherImage.getHeight()!=samesImage.getHeight()){
            return false;
        }
        
        int[] otherPixel = new int[1];
        int[] samesPixel = new int[1];
        
        int width = samesImage.getWidth();
        int height = samesImage.getHeight();
        
        int numDiffPixels = 0;
        // Now, go through pixel-by-pixel and check that the images are the same;
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                if (samesImage.getRGB(x, y) != otherImage.getRGB(x, y)) {
                    System.out.println(samesImage.getRGB(x, y)+":"+otherImage.getRGB(x, y));
                    numDiffPixels++;
                }
            }
        }
        double numberPixels = (height * width);
        double diffPercent = numDiffPixels / numberPixels;
        
        return percent <= 1.0 - diffPercent;
    }
}
cs



 하지만, 왜 차이가 생기는지는 잘 모르겠다.


 값이 동일하게 나온 것이라고 생각하는데...


 일단, 이렇게 구현을 할 수 있다면, 특정 위치를 조작해서 처리할 수 있는 방법도 만들 수 있다.

Posted by JunkMam
,