just trying to do a simple openCV android program. Downloaded and installed OpenCV for Android following the instructions here and added the OpenCV Library 2.4.2 as a librar
The solution is to either do like in @Jason answer which is about using the OpenCV Manager. It is also explained in great detail on the official documentation here.
But like @Jason says, "Makes it so the user has to install severally packages manually before the app will work". Although this is true, OpenCV Manager has some advantages like for example:
If OpenCV is updated, the user only needs to update the manager/library. The applications which use the manager can remain the same.
Your app apk size will be a lot smaller:
Even so, if you wish to deploy your apps the traditional way, static linking, you can read the instructions here.
Figured it out. Wasn't statically linking the library. If you use this code instead, it works.
package com.example;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class HelloAndroidActivity extends Activity
{
final String TAG = "Hello World";
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
// Create and set View
setContentView(R.layout.main);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
Log.i(TAG, "Trying to load OpenCV library");
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mOpenCVCallBack))
{
Log.e(TAG, "Cannot connect to OpenCV Manager");
}
}
}
However, not too fond of this "OpenCV Manager" idea. Makes it so the user has to install several packages manually before the app will work.
static{System.loadLibrary("opencv_java3"); } //the name of the .so file, without the 'lib' prefix
You can statically load the open cv library everywhere in your activity. Search the .so file in your jniLibs folder and copy/paste it as argument of "loadLibrary" method without the lib prefix.