0

I am trying to load the Open CV Library to my Android Studio application. I need to make the circle detection in my application.

I used this tutorial to load this library: How to use opencv in android studio using gradle build tool? (the last one one this page).

Before running my program everything looks right. But when I am trying to run it I have an error:

   06-11 14:48:02.010    1349-1349/com.example.teczowka.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load opencv_java249: findLibrary returned null
        at java.lang.Runtime.loadLibrary(Runtime.java:365)
        at java.lang.System.loadLibrary(System.java:535)
        at com.example.teczowka.app.MojHough.process(MojHough.java:23)
        at com.example.teczowka.app.MainActivity.onOptionsItemSelected(MainActivity.java:98)
        at android.app.Activity.onMenuItemSelected(Activity.java:2534)
        at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:372)
        at android.support.v7.app.ActionBarActivity.superOnMenuItemSelected(ActionBarActivity.java:244)
        at android.support.v7.app.ActionBarActivityDelegateICS.onMenuItemSelected(ActionBarActivityDelegateICS.java:164)
        at android.support.v7.app.ActionBarActivity.onMenuItemSelected(ActionBarActivity.java:130)
        at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onMenuItemSelected(ActionBarActivityDelegateICS.java:308)
        at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:958)
        at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
        at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
        at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
        at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:156)
        at android.widget.AdapterView.performItemClick(AdapterView.java:298)
        at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
        at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
        at android.widget.AbsListView$1.run(AbsListView.java:3529)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

I've tried almost everything and I have no idea what is going on. I've spent all day to figure it out - with no result. Can anyone help me ?

Here is my code:

  public Bitmap process(Bitmap src) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat imgSource = new Mat();
    Mat imgCirclesOut = new Mat();
    Utils.bitmapToMat(src, imgSource);

    //grey opencv
    Imgproc.cvtColor(imgSource, imgSource, Imgproc.COLOR_BGR2GRAY);

    Imgproc.GaussianBlur(imgSource, imgSource, new Size(9, 9), 2, 2);
    Imgproc.HoughCircles(imgSource, imgCirclesOut, Imgproc.CV_HOUGH_GRADIENT, 1, imgSource.rows() / 8, 200, 100, 0, 0);

    float circle[] = new float[3];

    for (int i = 0; i < imgCirclesOut.cols(); i++) {
        imgCirclesOut.get(0, i, circle);
        org.opencv.core.Point center = new org.opencv.core.Point();
        center.x = circle[0];
        center.y = circle[1];
        Core.circle(imgSource, center, (int) circle[2], new Scalar(255, 0, 0, 255), 4);
    }
    Bitmap bmp = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);

    Utils.matToBitmap(imgSource, bmp);
    return bmp;
}
1

2 Answers 2

2

first of all try to load all your libraries in a static block

static{
    OpenCVLoader.initDebug();
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}

and also check your apk file to make sure that opencv libraries (*.so) are included in the apk. (try opening the apk with an archive viewer and look inside "libs" directory)

finally the library name is a little bit strange it usually is "libopencv_java.so" (for all opencv versions including 2.4.9) so I guess try loading that instead of Core.NATIVE_LIBRARY_NAME to see if anything happenes.

Sign up to request clarification or add additional context in comments.

1 Comment

It's weird that the official Core.java returns opencv_java249 for the Core.NATIVE_LIBRARY_NAME although the actual name is opencv_java.so. Anyhow, using OpenCVLoader.initDebug() should be enough - no need for System.loadLibrary(...).
0

I suggest you to add the Native Libraries to you project, the .so files. You need add to \lib\ folder in your project the platforms folders in this path: OpenCV-x.x.xx-android-sdk\sdk\native\libs\ - armeabi - armeabi-v7a - mips - x86

Which folder you need add depends in what is your target architecture, and this is how i solved the problem you have.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.