|
1 | 1 | import io.appium.java_client.TouchAction;
|
| 2 | +import library.AkazeImageFinder; |
| 3 | +import library.ImageRecognition; |
| 4 | + |
2 | 5 | import org.opencv.core.Point;
|
3 | 6 | import org.openqa.selenium.By;
|
4 | 7 | import org.openqa.selenium.Dimension;
|
@@ -37,83 +40,7 @@ public void setQueryImageFolder() {
|
37 | 40 | }
|
38 | 41 | }
|
39 | 42 |
|
40 |
| - /** |
41 |
| - * ====================================================================================== |
42 |
| - * FINDING AN IMAGE IN ANOTHER IMAGE |
43 |
| - * ====================================================================================== |
44 |
| - */ |
45 |
| - |
46 |
| - |
47 |
| - |
48 |
| - //This method calls on the Akaze scripts to find the coordinates of a given image in another image. |
49 |
| - //The "image" parameter is the image that you are searching for |
50 |
| - //The "scene" parameter is the image in which we are looking for "image" |
51 |
| - // "tolerance" sets the required accuracy for the image recognition algorithm. |
52 |
| - public Point[] findImage(String image, String scene, double tolerance) throws Exception { |
53 |
| - Point[] imgRect = new Point[0]; |
54 |
| - Point[] imgRectScaled; |
55 |
| - |
56 |
| - |
57 |
| - log("Searching for " + image); |
58 |
| - log("Searching in " + scene); |
59 |
| - try { |
60 |
| - imgRect = imageFinder.findImage(image, scene, tolerance); |
61 |
| - } catch (Exception e) { |
62 |
| - e.printStackTrace(); |
63 |
| - } |
64 |
| - |
65 |
| - if (imgRect != null) { |
66 |
| - Dimension size = getScreenSizeADB(); |
67 |
| - |
68 |
| - if (platformName.equalsIgnoreCase("iOS")) { |
69 |
| - //for retina devices we need to recalculate coordinates |
70 |
| - double sceneHeight = imageFinder.getSceneHeight(); |
71 |
| - double sceneWidth = imageFinder.getSceneWidth(); |
72 |
| - |
73 |
| - int screenHeight = size.getHeight(); |
74 |
| - int screenWidth = size.getWidth(); |
75 |
| - |
76 |
| - // Make sure screenshot size values are "landscape" for comparison |
77 |
| - if (sceneHeight > sceneWidth) { |
78 |
| - double temp = sceneHeight; |
79 |
| - sceneHeight = sceneWidth; |
80 |
| - sceneWidth = temp; |
81 |
| - } |
82 |
| - |
83 |
| - // Make sure screen size values are "landscape" for comparison |
84 |
| - if (screenHeight > screenWidth) { |
85 |
| - int temp = screenHeight; |
86 |
| - screenHeight = screenWidth; |
87 |
| - screenWidth = temp; |
88 |
| - } |
89 | 43 |
|
90 |
| - if ((screenHeight<sceneHeight) && (screenWidth<sceneWidth)) { |
91 |
| - if ((screenHeight<sceneHeight/2)&&(screenWidth<sceneWidth/2)) { |
92 |
| - imgRectScaled = new Point[]{new Point(imgRect[0].x / 3, imgRect[0].y / 3), new Point(imgRect[1].x / 3, imgRect[1].y / 3), new Point(imgRect[2].x / 3, imgRect[2].y / 3), new Point(imgRect[3].x / 3, imgRect[3].y / 3), new Point(imgRect[4].x / 3, imgRect[4].y / 3)}; |
93 |
| - log("Device with Retina display rendered at x3 => coordinates have been recalculated"); |
94 |
| - imgRect = imgRectScaled; |
95 |
| - } |
96 |
| - else { |
97 |
| - imgRectScaled = new Point[]{new Point(imgRect[0].x / 2, imgRect[0].y / 2), new Point(imgRect[1].x / 2, imgRect[1].y / 2), new Point(imgRect[2].x / 2, imgRect[2].y / 2), new Point(imgRect[3].x / 2, imgRect[3].y / 2), new Point(imgRect[4].x / 2, imgRect[4].y / 2)}; |
98 |
| - log("Device with Retina display rendered at x2 => coordinates have been recalculated"); |
99 |
| - imgRect = imgRectScaled; |
100 |
| - } |
101 |
| - } |
102 |
| - } |
103 |
| - |
104 |
| - Point center = imgRect[4]; |
105 |
| - |
106 |
| - // Check that found center coordinate isn't out of screen bounds |
107 |
| - if ((center.x >= size.width) || (center.x < 0) || (center.y >= size.height) || (center.y < 0)) { |
108 |
| - log("Screen size is (width, height): " + size.getWidth() + ", " + size.getHeight()); |
109 |
| - log("WARNING: Coordinates found do not match the screen --> image not found."); |
110 |
| - imgRect = null; |
111 |
| - } else { |
112 |
| - return imgRect; |
113 |
| - } |
114 |
| - } |
115 |
| - return null; |
116 |
| - } |
117 | 44 |
|
118 | 45 | /**
|
119 | 46 | * ======================================================================================
|
@@ -218,7 +145,7 @@ private ImageSearchDTO findImageLoop(String image, ImageRecognitionSettingsDTO s
|
218 | 145 | // queryImageFolder is "", unless set by setQueryImageFolder()
|
219 | 146 | String queryImageFile = "queryimages/" + queryimageFolder + image + "_screenshot";
|
220 | 147 | String screenshotFile = takeScreenshot(image + "_screenshot");
|
221 |
| - Point[] imgRect = findImage(queryImageFile, screenshotFile, settings.getTolerance()); |
| 148 | + Point[] imgRect = ImageRecognition.findImage(queryImageFile, screenshotFile, settings, platformName, getScreenSizeADB()); |
222 | 149 | if (imgRect!=null){
|
223 | 150 | long end_time = System.nanoTime();
|
224 | 151 | int difference = (int) ((end_time - start_time) / 1e6 / 1000);
|
|
0 commit comments