SURF& SIFT功能检测器OpenCV android

时间:2015-02-13 15:32:57

标签: android opencv feature-detection sift surf

我想检测图像关键点。我使用OpenCV库中的不同特征检测器尝试了以下代码。

适用于ORB,BRISK,FAST等 但不适用于SURF / SIFT甚至MSER探测器!

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

          }

这是因为不支持SURF和SIFT算法?

1 个答案:

答案 0 :(得分:2)

对于C ++版本,我们使用cv::initModule_nonfree()

这是因为在新版本的OpenCV中,SURF / SIFT算法很遗憾地位于一个单独的库中,需要在创建这些特征检测器之前对其进行初始化。