【问题标题】:OpenCV 2.4.5 android, FeatureDetector, DescriptorExtractorOpenCV 2.4.5 android、FeatureDetector、DescriptorExtractor
【发布时间】:2015-08-24 18:49:07
【问题描述】:

使用 OpenCV-2.4.5-android-sdk, 我尝试将两个图像与特征检测(ORB 检测器和汉明匹配器)进行匹配。不幸的是,我在计算描述符时总是得到 NullPointerException。我究竟做错了什么?

        FeatureDetector detector = FeatureDetector.create("ORB");
        DescriptorExtractor descriptor = DescriptorExtractor.create("ORB");
        BFMatcher matcher = new BFMatcher(Hamming.normType, true);

        KeyPoint keypoints1 = new KeyPoint();
        KeyPoint keypoints2 = new KeyPoint();
        CvMat[] descriptors = new CvMat[2];

        //ORB orb = new ORB();

        //orb.detect(image1, null, keypoints1);
        detector.detect(image1, keypoints1, null);
        descriptor.compute(image1, keypoints1, descriptors[0]);

        detector.detect(image2, keypoints2, null);
        //orb.detect(image2, null, keypoints2);
        descriptor.compute(image2, keypoints2, descriptors[1]);

        // matcher should include 2 different image's descriptors
        DMatch matches = new DMatch();
        matcher.match(descriptors[0], descriptors[1], matches, null);

我想知道,如果我在没有 android-ndk 的情况下在 Android 上使用 openCV 执行特征检测进行更改。您是否建议尝试编写和集成本机 C++ 代码?

更新:重组项目设置后,如下:http://docs.opencv.org/trunk/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#dev-with-ocv-on-android描述,代码如下:

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
    DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

    MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
    MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
    Mat[] descriptors = new Mat[2];

    //ORB orb = new ORB();
    //orb.detect(image1, null, keypoints1);
    detector.detect(image1, keypoints1, null);
    descriptor.compute(image1, keypoints1, descriptors[0]);

    detector.detect(image2, keypoints2, null);
    //orb.detect(image2, null, keypoints2);
    descriptor.compute(image2, keypoints2, descriptors[1]);

    // matcher should include 2 different image's descriptors
    MatOfDMatch matches = new MatOfDMatch();
    matcher.match(descriptors[0], descriptors[1], matches);

NPE 仍然发生。

【问题讨论】:

  • 我假设您在第一次出现 descriptor.compute 时遇到异常。尝试使用两个实例 descriptors1descriptors2 而不是 CvMat[]。如果没有帮助,请尝试打印detector.detect 之后的关键点数。
  • 感谢您的回答。你是对的,错误发生在第一次调用desriptor.compute。我试图有两个实例 descriptors1descriptors2 但后来我得到了 LogCat 输出:OpenCV Error: Bad argument (Unknown array type) in cv::Mat cv::cvarrToMat(const CvArr*, bool, bool, int), file /home/saudet/projects/javacv-cppjars/opencv-2.4.5/modules/core/src/matrix.cpp, line 698 在我的测试示例中,detector.detect 之后的 keypoints1 的大小为 31。我不确定,如果这是数量关键点。
  • 您是否尝试过使用Mat 来存储图像和描述符,而不是CvMatCvMat 现已过时;考虑改用Mat。它可能会解决异常问题。
  • 也感谢您的回答。我在opencv_corecom.googlecode.javacv.cpp 中找不到Mat。并且DescriptorExtractor 中的方法compute 具有签名void com.googlecode.javacv.cpp.opencv_features2d.DescriptorExtractor.compute(@InputMat CvArr arg0, @StdVector KeyPoint arg1, @OutputMat CvMat arg2)
  • 哦,你用的是JavaCV,我的错。

标签: android opencv javacv orb


【解决方案1】:

您似乎错过了将对象分配给descriptors[] 数组。

    descriptors[0] = new CvMat();
    descriptors[1] = new CvMat();

【讨论】:

    【解决方案2】:

    分配对象,例如。

    Mat descriptortwo = new Mat();
    

    然后从可选的掩码参数中删除空参数,如下所示:

    detector.detect(image1,keypoints1); 
    

    认为它应该可以解决问题:)

    【讨论】:

      【解决方案3】:

      尝试初始化 thouse 矩阵。 而不是说Mat[] descriptors = new Mat[2];

      尝试: Mat descriptors1= new Mat(); Mat descriptors2= new Mat();

      【讨论】:

        猜你喜欢
        • 2013-05-07
        • 1970-01-01
        • 1970-01-01
        • 2013-03-26
        • 2011-12-28
        • 1970-01-01
        • 1970-01-01
        • 2013-12-15
        • 1970-01-01
        相关资源
        最近更新 更多