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

Commit edaecd2

Browse files
author
Severi Haverila
committed
refactored library, no setup needed
1 parent a61af09 commit edaecd2

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

example/src/test/java/AndroidSample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public AndroidSample() throws Exception {
3333

3434
@BeforeClass
3535
public static void setUp() throws Exception {
36-
ImageRecognition.setUp();
3736
driver = getAndroidDriver();
3837
}
3938

example/src/test/java/iOSSample.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public iOSSample() throws Exception {
3030

3131
@BeforeClass
3232
public static void setUp() throws Exception {
33-
ImageRecognition.setUp();
3433
driver = getIOSDriver();
3534
}
3635

@@ -56,7 +55,7 @@ public void mainPageTest() throws Exception {
5655
}
5756

5857
findAndCropImage("test.png");
59-
// waitForImageToDisappearFromScreen("bitbar_logo.png");
6058
log("Success.");
6159
}
60+
6261
}

library/src/main/java/imagerecognition/AkazeImageFinder.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,13 @@ private String runAkazeMatch(String object_filename, String scene_filename) thro
377377
}
378378

379379
protected static void setupOpenCVEnv() {
380-
String platformName = System.getProperty("os.name");
381-
logger.info(platformName);
382-
if (platformName.toLowerCase().contains("mac")) {
383-
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + System.getProperty("user.dir") + "/lib/mac/opencv");
384-
} else if (platformName.toLowerCase().contains("win")) {
385-
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + System.getProperty("user.dir") + "/lib/win/opencv");
386-
} else {
387-
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + System.getProperty("user.dir") + "/lib/linux/opencv/java7");
388-
}
380+
addOpenCvToJavaLibraryPath();
381+
setSysPathAccessible();
382+
logger.info("java.library.path: " + System.getProperty("java.library.path"));
383+
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
384+
}
389385

386+
private static void setSysPathAccessible() {
390387
Field fieldSysPath = null;
391388
try {
392389
fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
@@ -398,8 +395,18 @@ protected static void setupOpenCVEnv() {
398395
fieldSysPath.set(null, null);
399396
} catch (IllegalAccessException e) {
400397
}
401-
logger.info("java.library.path: " + System.getProperty("java.library.path"));
402-
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
398+
}
399+
400+
private static void addOpenCvToJavaLibraryPath() {
401+
String platformName = System.getProperty("os.name");
402+
logger.info(platformName);
403+
if (platformName.toLowerCase().contains("mac")) {
404+
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + System.getProperty("user.dir") + "/lib/mac/opencv");
405+
} else if (platformName.toLowerCase().contains("win")) {
406+
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + System.getProperty("user.dir") + "/lib/win/opencv");
407+
} else {
408+
System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + System.getProperty("user.dir") + "/lib/linux/opencv/java7");
409+
}
403410
}
404411

405412
private JSONObject getJsonObject(String filename) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private static void log(String message) {
2626
logger.info(message);
2727
}
2828

29-
public static void setUp(){
29+
static {
3030
AkazeImageFinder.setupOpenCVEnv();
3131
}
3232

0 commit comments

Comments
 (0)