I am using OpenCV4Android version 2.4.10 and i test my code on Samsung Galayx GT-I9300. the problem i have is, that i must download Opencv Manager from play store so that my opencv code runs, otherwise the App would not start.
I referred to some postes "as shown here How to integrate OpenCV Manager in Android App" to know how can i run the opncv code on android without the need to download OpenCV manager
but unfortunately the App doesnt start as long as OpenCV Manager is not installed.
i tried the follwoing
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
}
}
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;
}
}
};
...
...
...
@Override
public void onResume() {
super.onResume();
Log.w(TAG, "onResume");
if (!OpenCVLoader.initDebug()) {
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_10, getActivity(), mLoaderCallback);
} else {
Log.d(TAG, "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
but that did not solve the problem.
Please let me know how to run opencv code on android without downloading Opencv Manager ?
Update:
use of initAsync:
would you please provide an example how to use "initAsync()" in the production version of the App? because i tried to do it but of course i cant use it in the static block because the signature of "intiAsync" is as follows "OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_10, this, mLoaderCallback);" and i cant use "this" keyword nor a reference to the callback "mLoaderCallback" inside the static block
public class MainActivity extends AppCompatActivity {
static {
//OpenCVLoader.initDebug();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_10, this, mLoaderCallback); //this keyword and "mLoaderCallback" are not defined in this scope
}
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.i("MainActivity", "OpenCV loaded successfully");
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Mat m = new Mat(100, 100, CvType.CV_8UC4);
Log.d("MainActivity", "m.width()" + m.width());
Log.d("MainActivity", "m.height()" + m.height());
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…