Android development with OpenCV tutorial not working

asked 2015-08-04 01:15:41 -0500

Tingke gravatar image

Hi There!

I am just following the OpenCV Android tutorial on the official webpage of OpenCV: http://docs.opencv.org/2.4.3/doc/tuto... and I mainly just copy-pasted the code but it doesn't seem to work. I keep getting the error: Error signal 11 (SIGSEGV) and it is always doing the initialization of a VideoCapture object. All help is much appreciated! Here is the activity:

public class helloWorldTutorial extends Activity {
private HelloOpenCVView mView;
private Context mContext;
public void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
}

public String TAG = "OpenCVLoading";
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");
                mView = new HelloOpenCVView(mContext);
                setContentView (mView);
                if( !mView.cameraOpen() ) {
                    // MessageBox and exit app
                    AlertDialog ad = new AlertDialog.Builder(mContext).create();
                    ad.setCancelable(false); // This blocks the "BACK" button
                    ad.setMessage("Fatal error: can't open camera!");
                    ad.setButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            finish();
                        }
                    });
                    ad.show();
                }
            } break;
            default:
            {
                super.onManagerConnected(status);
                Log.i(TAG, "OpenCV loaded Unsuccessfully");
            } break;
        }
    }
};

protected void onResume()
{
    Log.i(TAG, "called onResume");
    super.onResume();

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


// Here is the cameraOpen() function in the view class
public boolean cameraOpen() {
    synchronized (this) {
        cameraRelease();
        Log.e("HelloOpenCVView", "init vidCap");
        mCamera = new VideoCapture(-1);
        Log.e("HelloOpenCVView", "ugh");
        if (!mCamera.isOpened()) {
            mCamera.release();
            mCamera = null;
            Log.e("HelloOpenCVView", "Failed to open native camera");
            return false;
        }
    }
    return true;
}

    //Here is the log, the error being on the last line
    08-04 08:04:11.493    8506-8506/com.example.kevin.prototypev00 I/OpenCVLoading﹕ OpenCV loaded successfully
    08-04 08:04:11.493    8506-8506/com.example.kevin.prototypev00 E/HelloOpenCVView﹕ init vidCap
    08-04 08:04:11.493    8506-8506/com.example.kevin.prototypev00 D/OpenCV::camera﹕ CvCapture_Android::CvCapture_Android(-1)
    08-04 08:04:11.503    8506-8506/com.example.kevin.prototypev00 D/OpenCV::camera﹕ Library name: libopencv_java.so
    08-04 08:04:11.503    8506-8506/com.example.kevin.prototypev00 D/OpenCV::camera﹕ Library base address: 0x79e28000
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 D/OpenCV::camera﹕ Libraries folder found: /data/app-lib/org.opencv.engine-1/
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 D/OpenCV::camera﹕ CameraWrapperConnector::connectToLib: folderPath=/data/app-lib/org.opencv.engine-1/
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 E/OpenCV::camera﹕ ||libnative_camera_r4.3.0.so
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 E/OpenCV::camera﹕ ||libnative_camera_r4.0.3.so
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 E/OpenCV::camera﹕ ||libnative_camera_r4.4.0.so
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 E/OpenCV::camera﹕ ||libnative_camera_r2.3.3.so
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 E/OpenCV::camera﹕ ||libnative_camera_r4.2.0.so
    08-04 08:04:11.523    8506-8506/com.example.kevin.prototypev00 E/OpenCV::camera﹕ ||libnative_camera_r2.2.0.so
    08-04 08:04:11 ...
(more)
edit retag flag offensive close merge delete

Comments

I've been looking around the internet for a while now and I still have no clue what's going on... Maybe this line in the log gives a clue? I don't know,

08-04 08:04:11.833 8506-8506/com.example.kevin.prototypev00 D/OpenCV_NativeCamera﹕ Supported Cameras: (null)

Is it supposed to say (null) for supported cameras?

P.S. I have written a camera app using the standard android library and it has worked and I have tested some of the OpenCV samples like blob detection and they have also worked...

Tingke gravatar imageTingke ( 2015-08-04 01:18:31 -0500 )edit

OpenCV 2.4.3 is old... you should try the tutorials for 2.4.11 or 3.0

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-04 03:49:10 -0500 )edit

Thank you so much! WOW I can't believe I've been stuck on this for a week... Ugh how is someone new supposed to know that there's no backwards compatibility with older OpenCV code

Tingke gravatar imageTingke ( 2015-08-04 23:57:24 -0500 )edit

There is no such thing even on other big stuff, like windows 98 is not compatible with 10, or maybe even 10 is no more compatible with 98... am I wrong? IMHO you should keep close to the new thing, and updating your soft, don't stay longer than 2, or maximum 3 versions behind. The new ones are fixing bugs and improving stuffs.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-05 02:42:07 -0500 )edit