Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

SURF & SIFT feature detector and descriptor on OpenCV android

I want to detect image keypoints. I tried the following code with differents feature detectors from the OpenCV library.

It work for ORB , BRISK , FAST , etc. But not for SURF/SIFT and even MSER detector !

 public class ReadImaageActivity extends ActionBarActivity {

 Mat image ; File fileimage ;
 TimePicker time ; 
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i("activity", "OpenCV loaded successfully");

                    fileimage = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/7.jpg");

                    if (fileimage.exists())

                    image = Highgui.imread(fileimage.getAbsolutePath() ,Highgui.CV_LOAD_IMAGE_COLOR);

                    else Log.i("activity","dont exit")       ;


                //  

                    long startTime = System.nanoTime();

                    FeatureDetector fd= FeatureDetector.create(FeatureDetector.SURF);

                    MatOfKeyPoint keypoints= new MatOfKeyPoint(); 
                    try 
                    {

                    fd.detect(image, keypoints);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                    long endTime = System.nanoTime();

                    long duration = (endTime - startTime)/1000000;  //divide by 1000000 to get milliseconds.



                    if (!keypoints.empty())
                    {   

                        Log.i("Keypoints", "is not empty"); 


                        System.out.println("duration"+""+duration);


                        System.out.println("size"+""+keypoints.size());
                }
                    else
                            Log.i("Keypoints", "is not empty");
                /*
                    Mat descriptors=new Mat();
                    DescriptorExtractor dex =DescriptorExtractor.create(DescriptorExtractor.SURF);


                    {   


                    dex.compute(image, keypoints, descriptors);

                    long endTime = System.nanoTime();

                    long duration = (endTime - startTime)/1000000;  //divide by 1000000 to get milliseconds.
                    System.out.println(descriptors.size());
                    System.out.println("duration"+duration);
                    }
                    else System.out.println("a3");

                    */










                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_read_imaage);


 }

@Override
public void onResume()
{
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
}

          }

It is because SURF and SIFT algorithms are not supported?

SURF & SIFT feature detector and descriptor on OpenCV android

I want to detect image keypoints. I tried the following code with differents feature detectors from the OpenCV library.

It work for ORB , BRISK , FAST , etc. But not for SURF/SIFT and even MSER detector !

 public class ReadImaageActivity extends ActionBarActivity {

 Mat image ; File fileimage ;
 TimePicker time ; 
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    Log.i("activity", "OpenCV loaded successfully");

                    fileimage = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/7.jpg");

                    if (fileimage.exists())

                    image = Highgui.imread(fileimage.getAbsolutePath() ,Highgui.CV_LOAD_IMAGE_COLOR);

                    else Log.i("activity","dont exit")       ;


                //  

                    long startTime = System.nanoTime();

                    FeatureDetector fd= FeatureDetector.create(FeatureDetector.SURF);

                    MatOfKeyPoint keypoints= new MatOfKeyPoint(); 
                    try 
                    {

                    fd.detect(image, keypoints);

                } catch (Exception e) {
                    e.printStackTrace();
                }

                    long endTime = System.nanoTime();

                    long duration = (endTime - startTime)/1000000;  //divide by 1000000 to get milliseconds.



                    if (!keypoints.empty())
                    {   

                        Log.i("Keypoints", "is not empty"); 


                        System.out.println("duration"+""+duration);


                        System.out.println("size"+""+keypoints.size());
                }
                    else
                            Log.i("Keypoints", "is not empty");
                /*
                    Mat descriptors=new Mat();
                    DescriptorExtractor dex =DescriptorExtractor.create(DescriptorExtractor.SURF);


                    {   


                    dex.compute(image, keypoints, descriptors);

                    long endTime = System.nanoTime();

                    long duration = (endTime - startTime)/1000000;  //divide by 1000000 to get milliseconds.
                    System.out.println(descriptors.size());
                    System.out.println("duration"+duration);
                    }
                    else System.out.println("a3");

                    */










                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };
@SuppressLint("NewApi") @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_read_imaage);


 }

@Override
public void onResume()
{
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
}

          }

It the code is because SURF and SIFT algorithms are not supported? tested with my debvice ZTE Blade android 2.3.7