Ask Your Question
2

Async Initialization of OpenCV on Android using OpenCVManager

asked 2013-03-27 02:07:26 -0600

Torcellite gravatar image

updated 2013-03-27 10:50:56 -0600

My understanding on the OpenCV structure for Android is limited to whatever was on the site's content. So far, I know how to check for the OpenCV library on a device. What is currently stumping me is it's initialization.

This is my previous code :

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

Where compare() is a function dealing with OpenCV functions such as keypoint detection, descriptor extraction, etc.

Now if I don't call compare() from within the BaseLoader but from the onCreate() function and use OpenCVLoader.init(<params>) within compare() itself, the app crashes with the Unsatisfied Link Error. Could someone point out the correct method of initialization WITH code, please?

The error: 03-27 21:18:20.968: W/dalvikvm(1575): No implementation found for native Lorg/opencv/highgui/Highgui;.imread_1 (Ljava/lang/String;)J

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-03-27 03:52:04 -0600

rics gravatar image

Here is a sample program from the OpenCv code.

initAsync is called from onResume which uses BaseLoaderCallback. Then you could use your compare from CvCameraViewListener2 interface methods like onCameraFrame.

You can find similar examples in the android samples directory.

edit flag offensive delete link more

Comments

I would like to read an already existing image. So I'm reading it onto a Mat using Highui. What do I for that?

I've already checked the samples out. They don't help me.

Torcellite gravatar imageTorcellite ( 2013-03-27 07:50:30 -0600 )edit

Have a look at image-manipulations example. You could place OpenCv function calls in onCameraViewStarted as well.

rics gravatar imagerics ( 2013-03-27 08:59:51 -0600 )edit

I do not want to open camera view. Just compare images. What should my baseloader contain?

Torcellite gravatar imageTorcellite ( 2013-03-27 10:07:43 -0600 )edit
0

answered 2013-04-16 09:07:14 -0600

Torcellite gravatar image

I finally solved it! Apparently OpenCV crashes every time it's functions are called in the UI, so I did..

Something like this :

 public class Face extends Activity {
 private Bitmap bitmap;
 private int f = Crop.k;
 private ImageView tv;
 Mat m;
 private static final String    TAG                 = "OCVSample::Activity";

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

I would suggest you execute whatever function you're trying in an AsyncTask like in my project. Mat functions however can be declared without the risk of the UnsatisfiedLinkError exception in OpenCV functions. Functions called in the UI however experience this. At least this is what I've seen.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-27 02:07:26 -0600

Seen: 8,170 times

Last updated: Apr 16 '13