gpt4 book ai didi

java - Android 中的 System.loadLibrary

转载 作者:行者123 更新时间:2023-12-01 12:02:34 25 4
gpt4 key购买 nike

我用一个简单的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添加到构建路径中的新库中,并且作为 native 库我添加了.dll,但似乎对于android它不起作用。

最佳答案

正如您的评论中所说,您必须为 Android 架构编译库。 DLL 文件适用于 Windows。这就是为什么你的编译器找不到任何符号。

Android NDK允许您根据需要为不同的架构(例如armeabi、armeabi-v7a或x86)编译静态(.a)或共享(.so)库。

关于java - Android 中的 System.loadLibrary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27886092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com