Search code examples
androidopencvjavacvimage-stitchingopencv-stitching

ExceptionInInitializerError in Stitcher with JavaCV for Android


I am using this code for image stitching with JavaCV on Android:

public void ImageStitching() {
    Stitcher stitcher = Stitcher.createDefault(false);
    MatVector images = new MatVector(2);
    images.put(0,cvLoadImage("sample1.png"));
    images.put(1,cvLoadImage("sample2.png"));

    IplImage result = new IplImage(null);
    int status = stitcher.stitch(images,result);

    if( status == Stitcher.OK )
    {
        cvSaveImage("result.png", result);
    }
}

But when I execute it, the app crashes and the log shows the following error:

java.lang.ExceptionInInitializerError at ...

and the error points to the Stitcher initilization, the first line of my code. If I try to do Stitcher stitcher; it doesn't break, but I cannot do anything else since the stitcher is not initialized. If I try to initialize it to null it crashes with the same error.

Any idea about the problem? I have been searching for a while and all the people use that and it seems to work.


Solution

  • Ok, I got it.

    The problem was that the library opencv_stitching.so was only in the folder armeabi and I needed in the armeabi-v7a one. Not I can declare the stitcher and initialize it.