1

Am trying to use opencv in my android project. Here is a complete list of events i did over the past few weeks:

1- I used my mobile phone camera to take a picture stored it as bitmap
2- Ran face detection on it
3- Now i was supposed to use android opencv to highlight the edges in the face detection bitmap

I do not know much about ndk stuff. All I did was downloaded the android opencv sdk imported into my project workspace used this as library project for my application and am using the following code in my android application:

 Bitmap canny_image = Bitmap.createBitmap(bmFace.getWidth(), bmFace.getHeight(), Config.ARGB_8888);
        canny_image = bmFace.copy(Config.ARGB_8888, true); 
        Mat mImg = new Mat();
        Utils.bitmapToMat(canny_image,mImg);

        //Converting to grayscale
        Mat mGray = new Mat(mImg.rows(), mImg.cols(), CvType.CV_8UC1, new Scalar(0));
        Imgproc.cvtColor(mImg , mGray, Imgproc.COLOR_BGRA2GRAY, 4); 
        //Applying Canny
        Imgproc.Canny(mGray, mGray, 80, 90);

        //Converting back to 4 channel image
        Imgproc.cvtColor(mGray , mImg, Imgproc.COLOR_GRAY2RGBA, 4); 
        canny_image.recycle();
        System.gc();
        canny_image = Bitmap.createBitmap(mImg.cols(), mImg.rows(), Bitmap.Config.ARGB_8888); 
        Utils.matToBitmap(mImg, canny_image); 

However the logcat is showing unsatisfied link error. Now using the documentation from here.

In this link there is a point:

If your application project doesn’t have a JNI part, just copy the corresponding OpenCV native libs from <OpenCV-2.4.6-android-sdk>/sdk/native/libs/<target_arch> to your project directory to folder libs/<target_arch>.

In case of the application project with a JNI part, instead of manual libraries copying you need to modify your Android.mk file: add the following two code lines after the "include $(CLEAR_VARS)" and before "include path_to_OpenCV-2.4.6-android-sdk/sdk/native/jni/OpenCV.mk"

I did the same. In my application i made a folder libs and copied all the .so and .h files in the /sdk/native/libs/

but then again my library project does not contain the application.mk and android.mk files. Am totally messed up how to use opencv in my android application. I thought the linking problem was due to the fact that i have not loaded the library in my code but again when i use this code in my application it gives an exception:

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

Referenced from the same link as i mentioned above. Please experts help me on this. I need some serious help. Been stuck here for like almost a week. How can i successfully use opencv in my android application. What am i missing?

mmBs
  • 8,421
  • 6
  • 38
  • 46
Baba
  • 63
  • 2
  • 10
  • Put the file Android.mk and Application.mk – user1755546 Sep 02 '13 at 08:15
  • "i made a folder libs and copied all the .so and .h files in the /sdk/native/libs/" Just in case, be sure to keep the folder architecture from the `/sdk/native/libs` directory: you should have the `libs/armeabi`, `libs/armeabi-v7a`, etc folders. – mbrenon Sep 02 '13 at 09:32

1 Answers1

0

This error is shown when you are calling a library before initializing it. Refer here : Android UnsatisfiedLinkError with OpenCV 2.4.2. Refer to the comment thread beneath the correct answer. So let the library initialise and then add whatever you wish to do beneath "Log.i(TAG, "OpenCV loaded successfully");"

Community
  • 1
  • 1