gpt4 book ai didi

android - OpenCV 2.4.5 android, FeatureDetector, DescriptorExtractor

转载 作者:太空宇宙 更新时间:2023-11-03 21:47:21 24 4
gpt4 key购买 nike

使用 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 的情况下使用 openCV 在 Android 上执行特征检测。您会建议尝试编写和集成 native 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 仍然会发生。

最佳答案

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

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

关于android - OpenCV 2.4.5 android, FeatureDetector, DescriptorExtractor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17151401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com