System.loadLibrary 在 android
System.loadLibrary in android
我用一个简单的 java 程序做了这个
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("\nRunning FaceDetector");
String cascade= "img/test.xml";
String imgloc= "img/asd.png";
CascadeClassifier faceDetector = new CascadeClassifier(cascade);
Mat image = Highgui.imread(imgloc);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
String filename = "ouput.jpg";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
它从图像中检测人脸并输出检测到的人脸。现在我想将它包含到一个 android 项目中,但是 System.loadLibrary
正在制作我的应用程序。碰撞。我该如何解决这个问题?
这是崩溃日志
01-11 10:44:23.296: E/AndroidRuntime(1564): FATAL EXCEPTION: main
01-11 10:44:23.296: E/AndroidRuntime(1564): Process: com.tppa.detector, PID: 1564
01-11 10:44:23.296: E/AndroidRuntime(1564): java.lang.NoClassDefFoundError: org.opencv.core.Core
01-11 10:44:23.296: E/AndroidRuntime(1564): at com.tppa.detector.MainActivity.onCreate(MainActivity.java:25)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.Activity.performCreate(Activity.java:5231)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.access0(ActivityThread.java:135)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.os.Handler.dispatchMessage(Handler.java:102)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.os.Looper.loop(Looper.java:136)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.main(ActivityThread.java:5001)
01-11 10:44:23.296: E/AndroidRuntime(1564): at java.lang.reflect.Method.invokeNative(Native Method)
01-11 10:44:23.296: E/AndroidRuntime(1564): at java.lang.reflect.Method.invoke(Method.java:515)
01-11 10:44:23.296: E/AndroidRuntime(1564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-11 10:44:23.296: E/AndroidRuntime(1564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-11 10:44:23.296: E/AndroidRuntime(1564): at dalvik.system.NativeStart.main(Native Method)
01-11 10:44:23.304: W/ActivityManager(479): Force finishing activity com.tppa.detector/.MainActivity
01-11 10:44:23.452: D/dalvikvm(479): GC_FOR_ALLOC freed 543K, 23% free 6457K/8320K, paused 13ms, total 13ms
01-11 10:44:23.956: W/ActivityManager(479): Activity pause timeout for ActivityRecord{528f2d70 u0 com.tppa.detector/.MainActivity t8 f}
01-11 10:44:24.004: W/EGL_genymotion(655): eglSurfaceAttrib not implemented
01-11 10:44:33.080: E/WindowManager(479): Starting window AppWindowToken{529d5a4c token=Token{528e29fc ActivityRecord{528f2d70 u0 com.tppa.detector/.MainActivity t8}}} timed out
它工作简单 Java,我将 .jar 添加到构建路径中的新库中,作为本机库,我添加了 .dll,但似乎 android 它赢了没用。
正如您在评论中所说,您必须为 android 架构编译您的库。 DLL 文件用于 Windows。这就是为什么您的编译器找不到任何符号的原因。
Android NDK 允许您根据需要为不同的体系结构(例如 armeabi、armeabi-v7a 或 x86)编译静态 (.a) 或共享 (.so) 库。
我用一个简单的 java 程序做了这个
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("\nRunning FaceDetector");
String cascade= "img/test.xml";
String imgloc= "img/asd.png";
CascadeClassifier faceDetector = new CascadeClassifier(cascade);
Mat image = Highgui.imread(imgloc);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
String filename = "ouput.jpg";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
它从图像中检测人脸并输出检测到的人脸。现在我想将它包含到一个 android 项目中,但是 System.loadLibrary
正在制作我的应用程序。碰撞。我该如何解决这个问题?
这是崩溃日志
01-11 10:44:23.296: E/AndroidRuntime(1564): FATAL EXCEPTION: main
01-11 10:44:23.296: E/AndroidRuntime(1564): Process: com.tppa.detector, PID: 1564
01-11 10:44:23.296: E/AndroidRuntime(1564): java.lang.NoClassDefFoundError: org.opencv.core.Core
01-11 10:44:23.296: E/AndroidRuntime(1564): at com.tppa.detector.MainActivity.onCreate(MainActivity.java:25)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.Activity.performCreate(Activity.java:5231)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.access0(ActivityThread.java:135)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.os.Handler.dispatchMessage(Handler.java:102)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.os.Looper.loop(Looper.java:136)
01-11 10:44:23.296: E/AndroidRuntime(1564): at android.app.ActivityThread.main(ActivityThread.java:5001)
01-11 10:44:23.296: E/AndroidRuntime(1564): at java.lang.reflect.Method.invokeNative(Native Method)
01-11 10:44:23.296: E/AndroidRuntime(1564): at java.lang.reflect.Method.invoke(Method.java:515)
01-11 10:44:23.296: E/AndroidRuntime(1564): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
01-11 10:44:23.296: E/AndroidRuntime(1564): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
01-11 10:44:23.296: E/AndroidRuntime(1564): at dalvik.system.NativeStart.main(Native Method)
01-11 10:44:23.304: W/ActivityManager(479): Force finishing activity com.tppa.detector/.MainActivity
01-11 10:44:23.452: D/dalvikvm(479): GC_FOR_ALLOC freed 543K, 23% free 6457K/8320K, paused 13ms, total 13ms
01-11 10:44:23.956: W/ActivityManager(479): Activity pause timeout for ActivityRecord{528f2d70 u0 com.tppa.detector/.MainActivity t8 f}
01-11 10:44:24.004: W/EGL_genymotion(655): eglSurfaceAttrib not implemented
01-11 10:44:33.080: E/WindowManager(479): Starting window AppWindowToken{529d5a4c token=Token{528e29fc ActivityRecord{528f2d70 u0 com.tppa.detector/.MainActivity t8}}} timed out
它工作简单 Java,我将 .jar 添加到构建路径中的新库中,作为本机库,我添加了 .dll,但似乎 android 它赢了没用。
正如您在评论中所说,您必须为 android 架构编译您的库。 DLL 文件用于 Windows。这就是为什么您的编译器找不到任何符号的原因。
Android NDK 允许您根据需要为不同的体系结构(例如 armeabi、armeabi-v7a 或 x86)编译静态 (.a) 或共享 (.so) 库。