我試圖用兩個SIFT
描述符與我能想到的最簡單的代碼匹配,但OpenCV 3
一直拋出異常。無法將兩個SIFT描述符與OpenCV匹配
這是我的代碼:
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: error: (-215) _queryDescriptors.type() == trainDescType in function cv::BFMatcher::knnMatchImpl
OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in cv::batchDistance, file C:\buil ds\master_PackSlave-win32-vc12-shared\opencv\modules\core\src\stat.cpp, line 3608 Exception: C:\builds\master_PackSlave-win32-vc12-shared\opencv\modules\core\src\stat.cpp:3608: error: (-215) type == src2.type() && src1.cols == src2. cols && (type == CV_32F || type == CV_8U) in function cv::batchDistance
感謝
我建議使用:http://robwhess.github.io/opensift/。它非常快速且易於使用。 – qqibrow
在match()調用之前,您應該檢查描述符1或描述符2是否爲空。 –
感謝您的評論,但它們不是空的 – Itay