cout<<"类型1: "<<desc1.type()<<endl;
desc1.convertTo(desc1, CV_32F);
desc2.convertTo(desc2, CV_32F);
cout<<"类型2: "<<desc1.type()<<endl;
FlannBasedMatcher matcher;
vector< DMatch > matches;
vector< vector<DMatch> > m_knnMatches;
matches.clear();
const float minRatio=1.f / 1.5f;
matcher.knnMatch(desc1,desc2,m_knnMatches,2);
for (int i=0; i<m_knnMatches.size(); i++)
{
const DMatch& bestMatch=m_knnMatches[i][0];
const DMatch& betterMatch=m_knnMatches[i][1];
float distanceRatio=bestMatch.distance/betterMatch.distance;
if (distanceRatio<minRatio)
{
matches.push_back(bestMatch);
}
}
当使用KNN匹配时,注意它的接受的描述子的类型应该为CV_32F,所以需要转换到所需的类型上。
错误为:OpenCV Error: Unsupported format or combination of formats (type=0 ) in buildIndex_, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/flann/src/miniflann.cpp, line 299 terminate called after throwing an instance of ‘cv::Exception’ what(): /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/flann/src/miniflann.cpp:299: error: (-210) type=0 in function buildIndex_