Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Commit 1e9cae3

Browse files
author
Severi Haverila
committed
use local maven repo
1 parent 26859c7 commit 1e9cae3

File tree

5 files changed

+79
-24
lines changed

5 files changed

+79
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ application.apk
99
*.classpath
1010
*.project
1111
*.settings/
12+
.DS_Store
13+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Run Appium:
4141
```
4242
cd library
4343
mvn package
44-
cp target/image-recognition-library-2.0-SNAPSHOT.jar ../example/lib/image_recognition_library_test.jar
44+
mvn install:install-file -Dfile=target/mobile-opencv-image-recognition-library-1.0-SNAPSHOT.jar -DpomFile=pom.xml -Djavadoc=target/mobile-opencv-image-recognition-library-1.0-SNAPSHOT-javadoc.jar -Dsources=target/mobile-opencv-image-recognition-library-1.0-SNAPSHOT-sources.jar
4545
cd ../example
4646
4747
# Install OpenCV (change path according to your platform)

example/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
<dependencies>
99
<dependency>
1010
<groupId>com.testdroid</groupId>
11-
<artifactId>image-recognition-library</artifactId>
11+
<artifactId>mobile-opencv-image-recognition-library</artifactId>
1212
<version>1.0-SNAPSHOT</version>
13-
<scope>system</scope>
14-
<systemPath>${project.basedir}/lib/image_recognition_library_test.jar</systemPath>
1513
</dependency>
1614
<dependency>
1715
<groupId>ch.qos.logback</groupId>
@@ -62,6 +60,14 @@
6260
<reportsDirectory>${project.build.directory}/reports/junit</reportsDirectory>
6361
</configuration>
6462
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-eclipse-plugin</artifactId>
66+
<configuration>
67+
<downloadSources>true</downloadSources>
68+
<downloadJavadocs>true</downloadJavadocs>
69+
</configuration>
70+
</plugin>
6571
</plugins>
6672
</build>
6773
</project>

library/pom.xml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@
66
<artifactId>mobile-opencv-image-recognition-library</artifactId>
77
<version>1.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
9-
109
<name>OpenCV Mobile Image Recognition Library</name>
1110
<description>Library for image recognition that can be used in mobile testing with for example Appium</description>
12-
<url></url>
13-
11+
<url>https://github.com/bitbar/testdroid-samples/tree/master/image-recognition/</url>
1412
<licenses>
1513
<license>
1614
<name>Apache License, Version 2.0</name>
1715
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
1816
<distribution>repo</distribution>
1917
</license>
2018
</licenses>
21-
2219
<scm>
2320
<url>https://github.com/severi/opencv_library</url>
2421
</scm>
25-
2622
<dependencies>
2723
<dependency>
2824
<groupId>net.sourceforge.tess4j</groupId>
@@ -66,32 +62,40 @@
6662
<artifactId>maven-compiler-plugin</artifactId>
6763
<version>3.6.0</version>
6864
<configuration>
69-
<source>1.7</source>
70-
<target>1.7</target>
65+
<source>1.8</source>
66+
<target>1.8</target>
7167
</configuration>
7268
</plugin>
7369
<plugin>
7470
<groupId>org.apache.maven.plugins</groupId>
75-
<artifactId>maven-surefire-plugin</artifactId>
76-
<version>2.19.1</version>
77-
<configuration>
78-
<reportsDirectory>${project.build.directory}/reports/junit</reportsDirectory>
79-
</configuration>
71+
<artifactId>maven-source-plugin</artifactId>
72+
<version>3.0.1</version>
73+
<executions>
74+
<execution>
75+
<id>attach-sources</id>
76+
<goals>
77+
<goal>jar</goal>
78+
</goals>
79+
</execution>
80+
</executions>
8081
</plugin>
82+
8183
<plugin>
8284
<groupId>org.apache.maven.plugins</groupId>
83-
<artifactId>maven-shade-plugin</artifactId>
84-
<version>2.3</version>
85+
<artifactId>maven-javadoc-plugin</artifactId>
86+
<version>2.10.4</version>
8587
<executions>
86-
<!-- Run shade goal on package phase -->
8788
<execution>
88-
<phase>package</phase>
89+
<id>attach-javadocs</id>
8990
<goals>
90-
<goal>shade</goal>
91+
<goal>jar</goal>
9192
</goals>
9293
</execution>
9394
</executions>
95+
<configuration>
96+
<additionalparam>-Xdoclint:none</additionalparam>
97+
</configuration>
9498
</plugin>
9599
</plugins>
96100
</build>
97-
</project>
101+
</project>

library/src/main/java/imagerecognition/ImageRecognition.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,29 @@ private static void log(String message) {
2929
AkazeImageFinder.setupOpenCVEnv();
3030
}
3131

32+
33+
/**
34+
* Find the location of the reference image on the screen
35+
*
36+
* @param searchedImageFilePath Path to the reference image file to be searched
37+
* @param sceneImageFilePath Path to the scene file in which the image is going to be searched for
38+
* @param platform Defines the platform (phone operating system) that is in use. PlatformType.ANDROID for Android and PlatformType.IOS for iOS
39+
* @return Returns the location of the image or null if image has not been found
40+
*/
3241
public static ImageLocation findImage(String searchedImageFilePath, String sceneImageFilePath, PlatformType platform) throws Exception {
3342
ImageRecognitionSettings setting = new ImageRecognitionSettings();
3443
return findImage(searchedImageFilePath, sceneImageFilePath, setting, platform);
3544
}
3645

46+
/**
47+
* Find the location of the reference image on the screen
48+
* @param searchedImageFilePath Path to the reference image file to be searched
49+
* @param sceneImageFilePath Path to the scene file in which the image is going to be searched for
50+
* @param settings Image recognition related settings
51+
* @param platform Defines the platform (phone operating system) that is in use. PlatformType.ANDROID for Android and PlatformType.IOS for iOS
52+
* @return Returns the location of the image or null if image has not been found
53+
* @throws Exception
54+
*/
3755
public static ImageLocation findImage(String searchedImageFilePath, String sceneImageFilePath, ImageRecognitionSettings settings, PlatformType platform) throws Exception {
3856
log("Searching for " + searchedImageFilePath);
3957
log("Searching in " + sceneImageFilePath);
@@ -95,6 +113,15 @@ private static boolean isPointInsideScreenBounds(Point center, Dimension screenS
95113
}
96114

97115

116+
/**
117+
* Checks whether image disappears from screen before a predefined timeout.
118+
*
119+
* @param searchedImageFilePath Path to the reference image file to be searched
120+
* @param screenshotBaseDirectory Path to the directory in which the screenshots should be stored
121+
* @param platform Defines the platform (phone operating system) that is in use. PlatformType.ANDROID for Android and PlatformType.IOS for iOS
122+
* @return True if the image cannot be found or disappears successfully. False if the image can be found and the function timeouts.
123+
* @throws Exception
124+
*/
98125
public static boolean hasImageDissappearedFromScreenBeforeTimeout(String searchedImageFilePath,
99126
String screenshotBaseDirectory, PlatformType platform) throws Exception {
100127
log("==> Trying to find image: " + searchedImageFilePath);
@@ -114,6 +141,12 @@ public static boolean hasImageDissappearedFromScreenBeforeTimeout(String searche
114141
return false;
115142
}
116143

144+
/**
145+
* Extract text from an image.
146+
*
147+
* @param imageInput Path to the image file in which a text should be found
148+
* @return The found text in the image.
149+
*/
117150
public static String getTextStringFromImage(String imageInput) {
118151
String[] tesseractCommand = {"tesseract", imageInput, "stdout"};
119152
String value = "";
@@ -137,8 +170,18 @@ public static String getTextStringFromImage(String imageInput) {
137170

138171

139172

140-
public static ImageSearchResult findImageOnScreen(String searchedImagePath, String screenshotBaseDirectory, ImageRecognitionSettings settings, PlatformType platform) throws InterruptedException, IOException, Exception {
141-
ImageSearchResult imageSearchResult = findImageLoop(searchedImagePath, screenshotBaseDirectory, settings, platform);
173+
/**
174+
* @param searchedImageFilePath Path to the reference image file to be searched
175+
* @param screenshotBaseDirectory Path to the directory in which the screenshots should be stored
176+
* @param settings Image recognition related settings
177+
* @param platform Defines the platform (phone operating system) that is in use. PlatformType.ANDROID for Android and PlatformType.IOS for iOS
178+
* @return ImageSearchResult, an object containing information about the location of the found image and a screenshot from the moment the reference image was found.
179+
* @throws InterruptedException
180+
* @throws IOException
181+
* @throws Exception
182+
*/
183+
public static ImageSearchResult findImageOnScreen(String searchedImageFilePath, String screenshotBaseDirectory, ImageRecognitionSettings settings, PlatformType platform) throws InterruptedException, IOException, Exception {
184+
ImageSearchResult imageSearchResult = findImageLoop(searchedImageFilePath, screenshotBaseDirectory, settings, platform);
142185
if (imageSearchResult.isFound() && settings.isCrop()) {
143186
log("Cropping image..");
144187
imageFinder.cropImage(imageSearchResult);

0 commit comments

Comments
 (0)