1

I am new to OpenCV, but I believe that I have everything set up correctly by following the instructions on this page link

Basically, my app crashes whenever I try to access anything from the OpenCV library from activity.

Take the following code snippet as an example:

Mat src = new Mat(100, 100, CvType.CV_8UC4);

here I'm just trying to initialise a matrix. When I debug the code, it goes into the Mat.class file, then it will throw a 'Invocation TargetException' saying 'The source attachment does not contain the source for the file Invocation TargetException.class.'

I have searched for solutions exhaustively on the Internet but couldn't find a satisfactory one and I've been stuck on this issue for weeks. If any further information is required please let me know. Many thanks in advance!

Note: I call OpenCVLoader at the very beginning and it returns true, and I have the following code snippet taken from the sample OpenCV app:

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
        case LoaderCallbackInterface.SUCCESS: {
            // TODO: test
            System.loadLibrary("img_proc_utils");
        }
            break;
        default: {
            super.onManagerConnected(status);
        }
            break;
        }
    }
};
2easy4sam
  • 11
  • 6
  • Can you post the error in LogCat? . Check if you call any opencv functions in onCreate() method . If yes,move it to onCameraViewStarted() or inside the case LoaderCallbackInterface.SUCCESS – Darshan Jul 21 '14 at 08:23
  • @Darshan as soon as the debugger goes into Mat.class, I get 'No implementation found for native Lorg/opencv/core/Mat;.n_Mat:(III)J' in LogCat – 2easy4sam Jul 21 '14 at 10:02
  • also I just noticed that although OpenCVLoader.initAsync returns true, mLoaderCallback is never called – 2easy4sam Jul 21 '14 at 10:10
  • If your application project doesn’t have a JNI part, just copy the corresponding OpenCV native libs from /sdk/native/libs/ to your project directory to folder libs/. So that means copy the \armeabi, \armeabi-v7a, and \x86 folders. – Darshan Jul 21 '14 at 11:04
  • Please follow this[link](http://stackoverflow.com/questions/11939192/unsatisfied-link-error-opencv-for-android-non-native). It will solve your problem i suppose – Darshan Jul 21 '14 at 11:05
  • @Darshan thanks for your response. I have followed the steps given in that post but I'm still facing the same problem. Basically, I added 'libopencv_core.a' to 'libs/'. The debugger still goes into the Mat.class file and OpenCVLoader.initDebug() still returns false. Is it because that my code has a JNI part? Would removing the JNI folder and adding corresponding libs from '/sdk/native/libs/' solve the problem? – 2easy4sam Jul 21 '14 at 20:18
  • @Darshan I just noticed that 'libopencv_java.so' is not added to the libs folder after compiling, and if I add it manually it disappears after rebuild... could that be the cause of the problem? – 2easy4sam Jul 21 '14 at 22:08
  • If your application had a JNI part then it was not necessary to copy those files(Please read my second comment carefully). Are you able to run the prebuilt sample apps(the apk files with OpenCV4android SDK) ?. Try running those apps and see if you get the same error. – Darshan Jul 22 '14 at 07:30
  • 1
    @Darshan hi there I think I just fixed this issue. the problem was with my Android.mk file I added OPENCV_INSTALL_MODULES:=on and everything is working now. thanks for help :) – 2easy4sam Jul 22 '14 at 21:15
  • Please post the solution in answers section and accept it so that it will help others in future. :-) – Darshan Jul 23 '14 at 07:18

1 Answers1

0

It turned out to be a problem with my Android.mk. I included OPENCV_INSTALL_MODULES:=on and everything works like a charm now :)

2easy4sam
  • 11
  • 6