-
Notifications
You must be signed in to change notification settings - Fork 5
/
NativeLibraryLoader.java
33 lines (27 loc) · 972 Bytes
/
NativeLibraryLoader.java
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
package org.genericsystem.cv.utils;
import java.lang.invoke.MethodHandles;
import org.opencv.core.Core;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Helper class to wrap opencv native library loading.
*
* @author Pierrik Lassalas
*/
public class NativeLibraryLoader {
private static final String libraryPath = "/usr/local/share/OpenCV/java/libopencv_java330.so";
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
// Make sure the library is only loaded once?
public static void load() {
load(libraryPath);
}
public static void load(String nativeLibraryPath) {
try {
logger.info("java.library.path: {}", System.getProperty("java.library.path"));
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (UnsatisfiedLinkError e) {
logger.info("Unable to load from library path! Using absolute path instead ({})", nativeLibraryPath);
System.load(nativeLibraryPath);
}
}
}