2

OpenCV-2.4.5-android-sdk を使用して、2 つの画像を特徴検出 (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 は引き続き発生します。

4

3 に答える 3

1

descriptors[]配列へのオブジェクトの割り当てを逃したようです。

    descriptors[0] = new CvMat();
    descriptors[1] = new CvMat();
于 2014-03-25T22:50:09.323 に答える
0

オブジェクトを割り当てます。

Mat descriptortwo = new Mat();

次に、次のように、オプションのマスク パラメーターから null 引数を削除します。

detector.detect(image1,keypoints1); 

それはトリックを行うべきだと思います:)

于 2015-03-15T09:50:23.277 に答える
0

家の行列を初期化してみてください。と言う代わりにMat[] descriptors = new Mat[2];

試す: Mat descriptors1= new Mat(); Mat descriptors2= new Mat();

于 2015-08-24T10:49:07.527 に答える