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.

Community
  • 1
  • 1
alaa alzoubi
  • 1
  • 1
  • 5
  • Which line crashes? You should log it. – Kornel Feb 22 '15 at 08: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? – alaa alzoubi Feb 22 '15 at 08: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? – Kornel Feb 23 '15 at 10:50
  • please check, if you get null pointers for `featureDetector` and `descriptorExtractor` – berak Apr 19 '15 at 06:41
  • what does this code do? –  Jun 25 '16 at 05:36

2 Answers2

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);
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.

mkr
  • 91
  • 3
  • 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?! – alaa alzoubi Feb 24 '15 at 09:54