【问题标题】:Can't match two SIFT descriptors with OpenCV无法将两个 SIFT 描述符与 OpenCV 匹配
【发布时间】:2015-01-14 14:13:54
【问题描述】:

我正在尝试将两个 SIFT 描述符与我能想到的最简单的代码进行匹配,但 OpenCV 3 不断抛出异常。

这是我的代码:

cv::Mat img1 = imread(...); // Shortened for the example
cv::Mat img2 = imread(...); // Shortened for the example

std::vector<KeyPoint> keypoints1, keypoints2;
Ptr<SIFT> ptrSift = SIFT::create(200, 3, 0.07, 15);
Mat descriptors1, descriptors2;
ptrSift->detectAndCompute(img1, Mat(), keypoints1, descriptors1, false);
ptrSift->detectAndCompute(img2, Mat(), keypoints2, descriptors2, false);

上面的代码给我带来了很好的结果,我可以使用drawKeypoints 函数将其可视化。

然后我使用下面的代码来匹配描述符:

BFMatcher matcher;
std::vector< DMatch > matches;
matcher.match(descriptors1, descriptors2, matches);

但它一直在扔:

C:\builds\master_PackSlave-win32-vc12-shared\opencv\modules\features2d\src\matchers.cpp:722: 错误:(-215) _queryDescriptors.type() == trainDescType 在函数中 cv::BFMatcher::knnMatchImpl

OpenCV 错误:断言失败(类型 == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in cv::batchDistance, 文件 C:\构建 ds\master_PackSlave-win32-vc12-shared\opencv\modules\core\src\stat.cpp, 第 3608 行异常: C:\builds\master_PackSlave-win32-vc12-shared\opencv\modules\core\src\stat.cpp:3608: 错误:(-215) 类型 == src2.type() && src1.cols == src2。列 && (类型 == CV_32F ||在函数 cv::batchDistance 中键入 == CV_8U)

谢谢

【问题讨论】:

  • 我建议使用:robwhess.github.io/opensift。它非常快速且易于使用。
  • 您应该在 match() 调用之前检查描述符 1 或描述符 2 是否为空。
  • 感谢您的评论,但它们不是空的
  • 在您的描述符矩阵中是否有相应的描述符行,它们是零向量?我曾经遇到过这种情况。试试FlannBasedMatcher,据我所知它可以处理这种情况。
  • 仔细查看错误。检查两个图像是否:(1) 类型为 CV_32FCV_8U,(2) 它们两者 类型相同,(3) 每个图像的两列是否相同。

标签: c++ opencv image-processing computer-vision feature-detection


【解决方案1】:

很有趣,下面的代码 sn-p 很适合我:

cv::BFMatcher matcher;
std::vector<cv::DMatch> matches;

cv::Mat descriptors1 = cv::Mat::eye(10, 10, CV_32F);
cv::Mat descriptors2 = cv::Mat::eye(10, 10, CV_32F);
matcher.match(descriptors1, descriptors2, matches);

你能检查一下吗?您能否提供描述符的大小和类型?最后,您是否在发布/调试模式下都尝试过?

ps:你用的是哪个版本?您应该尝试使用最新版本覆盖并重新编译 matchers.cpp:https://github.com/Itseez/opencv/commits/master/modules/features2d/src/matchers.cpp

【讨论】:

  • 这似乎行得通。我猜矩阵不是CV_32F 就像之前在 cmets 中对原始问题提出的那样。现在我的SiftDescriptorExtractor 有问题...说代码没有实现...还是谢谢
猜你喜欢
  • 2017-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
  • 1970-01-01
相关资源
最近更新 更多