我一直在努力使SURF实施工作,我遇到了一些麻烦,现在我终于认为我得到了'正确',但我有一个小问题。 问题非常简单,我确信它很简单,但我无法解决。图像显示正确,除了匹配之外的所有内容都不会被绘制。这是我的代码。
#include <stdio.h>
#include "opencv2/xfeatures2d.hpp"
#include <opencv2/opencv.hpp>
#include "opencv2/features2d/features2d.hpp"
using namespace cv;
using namespace std;
int main(int argc, char** argv ){
if ( argc != 3 ) {
printf("usage: DisplayImage.out <Image1_Path> <Image2_Path>\n");
return -1;
}
Mat image, image2;
image = imread( argv[1], 0 );
image2 = imread(argv[2], 0);
if ( !image.data ){
printf("No image data \n");
return -1;
}
if ( !image2.data ){
printf("No image data \n");
return -1;
}
/*
Ptr<FeatureDetector> detector = FastFeatureDetector::create(15);
vector<KeyPoint> keypoints1, keypoints2;
detector->detect(image, keypoints1);
detector->detect(image2, keypoints2);
Ptr<xfeatures2d::SURF> extractor = xfeatures2d::SURF::create();
Mat descriptors1, descriptors2;
extractor->compute(image, keypoints1, descriptors1);
extractor->compute(image2, keypoints2, descriptors2);
BFMatcher::BFMatcher matcher(L2<float>);
//BruteForceMatcher<L2<float> > matcher;
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
*/
Ptr<xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create();
vector<KeyPoint> keypoints1, keypoints2;
Mat descriptors1, descriptors2;
surf->detectAndCompute(image,noArray(), keypoints1, descriptors1, true);
//BFMatcher::BFMatcher matcher(L2<float>);
BFMatcher::BFMatcher matcher(NORM_HAMMING);
vector<DMatch> matches;
Mat res;
matcher.match(descriptors1,descriptors2, matches);
drawMatches(image, keypoints1, image2, keypoints2, matches, res);
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", res);
waitKey(0);
return 0;
}