MonkeyRunner을 이용해서 이미지를 분석할 수 있는데.(속도면에서 엄청 늦은 경우가 존재한다.)

 이것을 이용하기 위해서는 부분적으로 사진(이미지)을 잘라내서 사용하는 방법을 알아야 될 것이다.


 그래서 SubImage을 사용하는 방법을 작성하고자 한다.


 

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
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
        IChimpImage subImage = device.takeSnapshot().getSubImage(4040250250);
        subImage.writeToFile("out.png""png");
        
        device.dispose();
        
        System.exit(0);
    }
}
cs



 여기서 getSubImage는


 x위치, y위치, 넓이, 높이 이런 순으로 작성하면 된다.


 단, 여기서 생성되는 사각형이 현재 이미지의 전체의 위치로 옮겨 가면 안된다.


 예을 들어서 가로 100, 세로 100인 이미지에서 x위치 99에 넓이 100 이렇게 하면, 오작동이 일어나게 된다.

Posted by JunkMam
,

 MonkeyRunner을 연결해서 사용하는 것이 있게 된다.


 여기서, 이미지를 받아 들이고, 이미지를 비교하는 소스를 제작했다.


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
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");
        
        if(fileImage.sameAs(deviceImage, 0.75))
        {
            System.out.println("Sames");
        }
        else
        {
            System.out.println("Not");
        }
 
        device.dispose();
        
        System.exit(0);
    }
}
cs


 여기서 sameAs라는 것에서 1.0에 가까우면, 원본이랑 동일하게 보는 것이 맞다. 하지만, 제대로 동작이 안되는 경우가 있다.


 여기서, MonkeyRunner라는 분석이라고하여서 해당 소스를 올린 블로그가 있다.


 참조하면 도움이 될 것이다.


 http://goodtogreate.tistory.com/entry/monkeyrunner%EC%9D%98-%EB%B6%84%EC%84%9D

Posted by JunkMam
,