我根据http://opencv.itseez.com/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography使用FlannBasedMatcher。每次运行此行时,我都会收到错误“向量下标超出范围”“double dist = matches [i] .distance;”任何人都可以帮忙吗?我被困在这里已经有一段时间..
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect( img_object, keypoints_object );
detector.detect( img_scene, keypoints_scene );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene;
extractor.compute( img_object, keypoints_object, descriptors_object );
extractor.compute( img_scene, keypoints_scene, descriptors_scene );
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_object.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
答案 0 :(得分:0)
也许你的图像无法获得足够的功能?检查关键点的大小。
答案 1 :(得分:0)
你想用这个:
vector< vector<DMatch> > matches;
它是DMatch矢量的载体!
答案 2 :(得分:0)
如果您从未解决此问题,请确保使用正确类型的向量,第一个应为std::vector
,而第二个为cv::vector
。因此,如果您没有使用任何名称空间,它应该如下所示:
std::vector<cv::vector<cv::DMatch>> matches;