如何在Android Studio中集成OpenCV库?

时间:2018-06-25 15:46:23

标签: android android-studio opencv

我无法将opencv库初始化到我的项目中,我尝试了在线解决方案,但仍收到未实现org.opencv.core.Mat.n_Mat()的错误。请告诉我如何解决此错误。

06-25 21:05:17.260 1108-1108/com.tsg.carco E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.tsg.carco, PID: 1108
                                                             java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_Mat() (tried Java_org_opencv_core_Mat_n_1Mat and Java_org_opencv_core_Mat_n_1Mat__)
                                                                 at org.opencv.core.Mat.n_Mat(Native Method)
                                                                 at org.opencv.core.Mat.<init>(Mat.java:24)
                                                                 at com.tsg.carco.activities.CameraActivity.getObjectDetector(CameraActivity.java:842)
                                                                 at com.tsg.carco.activities.CameraActivity.autoCaptureForm(CameraActivity.java:810)
                                                                 at com.tsg.carco.activities.CameraActivity.access$300(CameraActivity.java:83)
                                                                 at com.tsg.carco.activities.CameraActivity$1.onPreviewFrame(CameraActivity.java:1051)
                                                                 at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1124)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                 at android.os.Looper.loop(Looper.java:164)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:6938)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
06-25 21:05:17.460 1108-1121/com.tsg.carco E/zygote: No implementation found for void org.opencv.core.Mat.n_delete(long) (tried Java_org_opencv_core_Mat_n_1delete and Java_org_opencv_core_Mat_n_1delete__J)
06-25 21:05:17.460 1108-1121/com.tsg.carco E/System: Uncaught exception thrown by finalizer
06-25 21:05:17.461 1108-1121/com.tsg.carco E/System: java.lang.UnsatisfiedLinkError: No implementation found for void org.opencv.core.Mat.n_delete(long) (tried Java_org_opencv_core_Mat_n_1delete and Java_org_opencv_core_Mat_n_1delete__J)
                                                         at org.opencv.core.Mat.n_delete(Native Method)
                                                         at org.opencv.core.Mat.finalize(Mat.java:911)
                                                         at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
                                                         at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
                                                         at java.lang.Daemons$Daemon.run(Daemons.java:103)
                                                         at java.lang.Thread.run(Thread.java:764)

这是我的代码,用于初始化openCV

Mat image = new Mat();
        Bitmap bitmap = null;
        File file;
        if (App.mObjectDetector == null || sToggleMode) {
            String path = null;
            if (!sToggle) {
                sToggle = true;
                String fileName = sFormState + ".jpg";
                path = getFilesDir() + File.separator + sFormRevision + File.separator + fileName;
                sFormRevision = AppInfo.mReport.mReportId.substring(0, 3).toLowerCase();
                file = new File(path);
                sToggleMode = file.exists();
                if (!sToggleMode) {
                    sToggle = false;
                    if (!getSecondaryObjectDetectionFile()) {
                        App.mLogger.d("Using default form for object detection");
                        getDefaultObjectDetector(image);
                    }
                } else {
                    App.mLogger.d("Using custom form for object detection: " + path);
                    bitmap = BitmapFactory.decodeFile(path);
                }
            } else {
                sToggle = false;
                if (!getSecondaryObjectDetectionFile()) {
                    App.mLogger.d("Using default form for object detection");
                    getDefaultObjectDetector(image);
                }
            }
            if (bitmap != null) {
                try {
                    Utils.bitmapToMat(bitmap, image);
                    cvtColor(image, image, Imgproc.COLOR_RGB2BGR);
                    App.mObjectDetector = new ObjectDetector(image);
                    if (App.DEBUG) {
                        String debugFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                                .getAbsolutePath() + File.separator + "CARCO" + File.separator + "DebugSample.jpg";
                        App.CopyFile(path, debugFile);
                    }
                } catch (Exception e) {
                    App.mLogger.w(e.getMessage());
                }
            } else {
                App.mLogger.d("CameraActivity-Camera: There is no sample form on this device at: " + path);
            }
        }

0 个答案:

没有答案