我在一个简单的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.access$800(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它不起作用。
答案 0 :(得分:1)
正如您在评论中所说,您必须为Android体系结构编译您的库。 DLL文件适用于Windows。这就是你的编译器找不到任何符号的原因。
Android NDK允许您根据需要为不同的架构编译静态(.a)或共享(.so)库,例如armeabi,armeabi-v7a或x86。