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;
}