我有一个立体相机设置,我试图匹配两个帧之间的功能,以便我可以将相应的点三角测量到一个三维点云。 它有点用,使用SURF,但实时使用太慢。有更快的方法吗?或者,解决问题的方法?
这是我的代码:
bool matchFeatures(Mat img_1, Mat img_2)
{
points_2D_left.clear();
points_2D_right.clear();
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400; SurfFeatureDetector detector(minHessian);
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect(img_1, keypoints_1);
detector.detect(img_2, keypoints_2);
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;
extractor.compute(img_1, keypoints_1, descriptors_1);
extractor.compute(img_2, keypoints_2, descriptors_2);
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match(descriptors_1, descriptors_2, matches);
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for (int i = 0; i < descriptors_1.rows; i++)
{
double dist = matches[i].distance;
if (dist < min_dist) min_dist = dist;
if (dist > max_dist) max_dist = dist;
}
std::vector< DMatch > good_matches;
for (int i = 0; i < descriptors_1.rows; i++)
{
if (matches[i].distance <= max(2 * min_dist, 0.02))
{
good_matches.push_back(matches[i]);
}
}
for (int i = 0; i < good_matches.size(); i++)
{
//-- Get the keypoints from the good matches
points_2D_left.push_back(keypoints_1[good_matches[i].queryIdx].pt);
points_2D_right.push_back(keypoints_2[good_matches[i].trainIdx].pt);
}
return true;
}