0

I'm working on a feature extraction/matching app using opencv on android using android studio .. I followed these steps for using native code in order to use SIFT or SURF algorithms.. I have copied the folders (armeabi, armeabi-v7a, ...etc) to the jniLibs folder and here is my code for the main methods

public class MainActivity extends Activity implements CvCameraViewListener2{

private Mat                    mRgba;
private Mat                    mGrayMat;
private CameraBridgeViewBase   mOpenCvCameraView;

Mat descriptors ;
List<Mat> descriptorsList;

FeatureDetector featureDetector;
MatOfKeyPoint keyPoints;
DescriptorExtractor descriptorExtractor;
DescriptorMatcher descriptorMatcher;

boolean mIsJavaCamera = true;
static {System.loadLibrary("opencv_java");}

////////////////////////////////////////////////////////////////
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 onCameraViewStarted(int width, int height) {

    mRgba = new Mat();
    mGrayMat = new Mat();
    featureDetector=FeatureDetector.create(FeatureDetector.SIFT);
         descriptorExtractor=DescriptorExtractor.create(DescriptorExtractor.SURF);
    descriptorMatcher=DescriptorMatcher.create(6);
    keyPoints = new MatOfKeyPoint();
    descriptors = new Mat();
 }

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    final Mat rgba = inputFrame.rgba();

   Imgproc.cvtColor(rgba, rgba, Imgproc.COLOR_RGBA2GRAY);
   featureDetector.detect(rgba, keyPoints);
   Features2d.drawKeypoints(rgba, keyPoints, rgba);
   return rgba;
}

when I compile and run the app it runs for less than one second then crashes. what is your recommendation?? (I'm using Android studio 1.1 NOT Eclipse).

thanks in advance.

5
  • Which line crashes? You should log it. Commented Feb 22, 2015 at 8:24
  • the app itself crashes.. this happens when only using SURF/SIFT detectors. for the same code above, when I use detectors like STAR, FREAK, ORB the app works fine.. the problem is that SURF/SIFT are in native C++.. but how to use them correctly? Commented Feb 22, 2015 at 8:41
  • Based on your code it's impossible to predict the reason of crash. Does featureDetector and descriptorExtractor instantiated correctly for SURF/SIFT? And where is you native code? Commented Feb 23, 2015 at 10:50
  • please check, if you get null pointers for featureDetector and descriptorExtractor Commented Apr 19, 2015 at 6:41
  • what does this code do? Commented Jun 25, 2016 at 5:36

2 Answers 2

1

You are Using BaseLoaderCallback method but you're missing the OPENCV Initialization.

Include following line of code in your onCreate Then you will be able to access the OPENCV CODE.

OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
Sign up to request clarification or add additional context in comments.

Comments

0

Just an educated guess from me: are you sure the SIFT and SURF implementations are compiled into the libs you are using? They detectors/descriptors are patent protected, and as such included in the 'nonfree' part of OpenCV. The fact, that other detection/description methods work okay seems to support this. See here for more info.

1 Comment

this is the main point for me, actually I'm not sure if they are correctly compiled or not. Unfortunately, I don't know how?!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.