Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

android - No implementation found for long org.opencv.core.Mat.n_Mat() error Using OpenCV

I am using OpenCV for adaptiveThreshold. My code for image processing using OpenCV is like this:

imageMat=new Mat();
Utils.bitmapToMat(bmp, imageMat);
Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_BGR2GRAY);
Imgproc.GaussianBlur(imageMat, imageMat, new Size(3, 3), 0);
Imgproc.adaptiveThreshold(imageMat, imageMat, 255,Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 5, 4);

But I am getting an error while declaring Mat:

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.example.pial_pc.instantbookreview.ImageCapture$3.onPictureTaken(ImageCapture.java:105)

As I'm new to OpenCV, I am not clearly understanding the error. The entire Java class where this code belongs is here.

What should I do to eliminate the error?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have successfully eliminate the error and my app does not crash while executing this line imageMat=new Mat();

The reason for the error is that Android calls the "onCreate" method before loading the OpenCV4Android library.So i have used Async Initialization of OpenCV using OpenCVManager. I have created BaseLoaderCallback before onCreate method. And inside that i have declared new Mat() like this:

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i("OpenCV", "OpenCV loaded successfully");
                imageMat=new Mat();
            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};

Then in onResume() i have checked if OpenCV library have been loaded and initialized from within current application package or not. The codes are as follows:

public void onResume()
{
    super.onResume();
    if (!OpenCVLoader.initDebug()) {
        Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
    } else {
        Log.d("OpenCV", "OpenCV library found inside package. Using it!");
        mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
    }
}

And my error is gone. My full updated java class is here.

Reference links :

  1. Async Initialization of OpenCV on Android using OpenCVManager
  2. Tutorial1Activity.java

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...