Hello, I'm trying to statically init my openCV manager as shown here : Async Initialization. I've created a BaseLoaderCallback mLoaderCallback but when trying to use initAsync I get either 2 problems:
- If I use the code given in the example,
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, mLoaderCallback))
Eclipse tells me there is an error because "The method initAsync(String, Context, LoaderCallbackInterface) in the type OpenCVLoader is not applicable for the arguments (String, PFC_AVR, BaseLoaderCallback)" where PFC_AVR is my class
- If I follow the suggestion and change te code to:
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this, (org.opencv.android.LoaderCallbackInterface) mLoaderCallback))
A fatal error occurs when running my app and Eclipse gives me the log:
04-08 08:21:41.780: E/AndroidRuntime(2076): FATAL EXCEPTION: main
04-08 08:21:41.780: E/AndroidRuntime(2076): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pf/com.example.pf.PFC_AVR}: java.lang.ClassCastException: com.example.pf.PFC_AVR$1 cannot be cast to org.opencv.android.LoaderCallbackInterface
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.os.Looper.loop(Looper.java:137)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.ActivityThread.main(ActivityThread.java:4517)
04-08 08:21:41.780: E/AndroidRuntime(2076): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 08:21:41.780: E/AndroidRuntime(2076): at java.lang.reflect.Method.invoke(Method.java:511)
04-08 08:21:41.780: E/AndroidRuntime(2076): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:985)
04-08 08:21:41.780: E/AndroidRuntime(2076): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:752)
04-08 08:21:41.780: E/AndroidRuntime(2076): at dalvik.system.NativeStart.main(Native Method)
04-08 08:21:41.780: E/AndroidRuntime(2076): Caused by: java.lang.ClassCastException: com.example.pf.PFC_AVR$1 cannot be cast to org.opencv.android.LoaderCallbackInterface
04-08 08:21:41.780: E/AndroidRuntime(2076): at com.example.pf.PFC_AVR.onCreate(PFC_AVR.java:94)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.Activity.performCreate(Activity.java:4470)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
04-08 08:21:41.780: E/AndroidRuntime(2076): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
So I don't know what to do. I need to init this library in order to create "Mat" objets and keep on working...
An important note is that my class is a Java class which implements a Cordova Plugin. I've copied all libraries to "armeaby-v7a" folder and, in fact, log tells me:
04-08 08:21:40.870: D/OpenCV/StaticHelper(2076): First attempt to load libs
04-08 08:21:40.870: D/OpenCV/StaticHelper(2076): Trying to init OpenCV libs
04-08 08:21:40.870: D/OpenCV/StaticHelper(2076): Trying to load library opencv_java
04-08 08:21:40.870: D/dalvikvm(2076): Trying to load lib /data/data/com.example.pf/lib/libopencv_java.so 0x41576cd0
04-08 08:21:41.480: D/dalvikvm(2076): Added shared lib /data/data/com.example.pf/lib/libopencv_java.so 0x41576cd0
04-08 08:21:41.490: D/OpenCV/StaticHelper(2076): Library opencv_java loaded
04-08 08:21:41.490: D/OpenCV/StaticHelper(2076): First attempt to load libs is OK
Can anyone help me please??? This is such a frustrating thing... MANY THANKS! My full code is:
package com.example.pf;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.ml.CvSVM;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import org.apache.cordova.*;
public class PFC_AVR extends CordovaActivity {
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.i(TAG, "OpenCV loaded successfully");
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, this,
(org.opencv.android.LoaderCallbackInterface) mLoaderCallback)) {
Log.e(TAG, "Cannot connect to OpenCV Manager");
}
super.init();
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
// super.loadUrl("file:///android_asset/www/index.html");
}
static {
if (!OpenCVLoader.initDebug()) {
// Handle initialization error
} else {
Log.i(TAG, "static linking success");
}
}
}