【问题标题】:OpenCV DescriptorExtractor returns emptyOpenCV DescriptorExtractor 返回空
【发布时间】:2014-09-24 17:51:42
【问题描述】:

我正在尝试在 iOS 上使用 OpenCV 进行对象检测。我正在使用this code sample from the documentation

这是我的代码:

Mat src = imread("src.jpg");
Mat templ = imread("logo.jpg");

Mat src_gray;
cvtColor(src, src_gray, CV_BGR2GRAY);

Mat templ_gray;
cvtColor(templ, templ_gray, CV_BGR2GRAY);

int minHessian = 500;

OrbFeatureDetector detector(minHessian);

std::vector<KeyPoint> keypoints_1, keypoints_2;

detector.detect(src_gray, keypoints_1);
detector.detect(templ_gray, keypoints_2);

OrbDescriptorExtractor extractor;

Mat descriptors_1, descriptors_2;

extractor.compute(src_gray, keypoints_1, descriptors_1);
extractor.compute(templ_gray, keypoints_2, descriptors_2);

问题出在extractor.compute(src_gray, keypoints_1, descriptors_1); 行上,它使descriptors_1 始终为空。

srctempl 不为空。

有什么想法吗?

谢谢

【问题讨论】:

  • keypoints_1 是空的吗?
  • 是的,keypoints_1 是空的。
  • 那么你无法计算描述符,因此,descriptors_1 为空。
  • 好的,如果有垫子,为什么descriptors_1 是空的?
  • 哪个 Mat 不是空的?如果您的意思是输入图像不是空的,那可能是因为检测器没有找到任何关键点。可能是因为里面没有显着点或者检测器的参数(例如minHessian)不合适。

标签: ios opencv object-detection orb


【解决方案1】:

首先,我认为如果您想使用特征检测器和描述符,您必须了解它们的工作原理。 你可以看到这个话题,'Penelope'的回答比我能做的更好地解释了一切: https://dsp.stackexchange.com/questions/10423/why-do-we-use-keypoint-descriptors

在第一步之后,我认为您应该更好地了解 ORB 检测器/描述符的工作原理(如果您真的想使用它),它的参数是什么等。为此,您可以查看 opencv 文档和 ORB 论文:

http://docs.opencv.org/modules/features2d/doc/feature_detection_and_description.html https://www.willowgarage.com/sites/default/files/orb_final.pdf

我这样说是因为您在 ORB 检测器上设置了“minHessian”参数,而“minHessian”实际上是来自 SURF 检测器的参数。

无论如何,您的代码的问题不在于。尝试像您下面的示例一样加载您的图像:

Mat src = imread("src.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat templ = imread("logo.jpg", CV_LOAD_IMAGE_GRAYSCALE );

然后检测关键点:

detector.detect(src, keypoints_1);
detector.detect(templ, keypoints_2);

现在检查 keypoints_1 和 keypoints_2 是否不为空。如果他们要进行描述符提取!它应该工作

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2016-10-15
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 2019-01-06
    • 2013-09-19
    相关资源
    最近更新 更多