但是我想进行特征点提取并匹配,不知道怎么写那个代码,你们看这是我写的仅仅是提取两幅图并提取特征点并匹配的代码,这是可以用的。但是就是不知道怎么和kinect结合。
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include<opencv2/legacy/legacy.hpp>
using namespace cv;
using namespace std;
int main (){
Mat image1;
Mat image2;
Mat featureImage1;
Mat featureImage2;
image1= imread("church01.jpg");
image2= imread("church02.jpg");
vector<KeyPoint>keypoints1;
vector<KeyPoint>keypoints2;
SurfFeatureDetector surf(2500);
surf.detect(image1,keypoints1);
surf.detect(image2,keypoints2);
drawKeypoints(image1,keypoints1,featureImage1,Scalar(255,255,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(image2,keypoints2,featureImage2,Scalar(255,255,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
SurfDescriptorExtractor surfDesc;
Mat descriptors1;
surfDesc.compute(image1,keypoints1,descriptors1);
Mat descriptors2;
surfDesc.compute(image2,keypoints2,descriptors2);
BruteForceMatcher<L2<float>>matcher;
vector<DMatch>matches;
matcher.match(descriptors1,descriptors2,matches);
nth_element(matches.begin(),matches.begin()+24,matches.end());
matches.erase(matches.begin()+25,matches.end());
Mat imageMatches;
drawMatches(image1,keypoints1,image2,keypoints2,matches,imageMatches,Scalar(255,255,255));
namedWindow("surf Features1");
imshow("surf Features1",featureImage1);
namedWindow("surf Features2");
imshow("surf Features2",featureImage2);
namedWindow("匹配结果");
imshow("匹配结果",imageMatches);
waitKey(0);
}
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include<opencv2/legacy/legacy.hpp>
using namespace cv;
using namespace std;
int main (){
Mat image1;
Mat image2;
Mat featureImage1;
Mat featureImage2;
image1= imread("church01.jpg");
image2= imread("church02.jpg");
vector<KeyPoint>keypoints1;
vector<KeyPoint>keypoints2;
SurfFeatureDetector surf(2500);
surf.detect(image1,keypoints1);
surf.detect(image2,keypoints2);
drawKeypoints(image1,keypoints1,featureImage1,Scalar(255,255,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(image2,keypoints2,featureImage2,Scalar(255,255,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
SurfDescriptorExtractor surfDesc;
Mat descriptors1;
surfDesc.compute(image1,keypoints1,descriptors1);
Mat descriptors2;
surfDesc.compute(image2,keypoints2,descriptors2);
BruteForceMatcher<L2<float>>matcher;
vector<DMatch>matches;
matcher.match(descriptors1,descriptors2,matches);
nth_element(matches.begin(),matches.begin()+24,matches.end());
matches.erase(matches.begin()+25,matches.end());
Mat imageMatches;
drawMatches(image1,keypoints1,image2,keypoints2,matches,imageMatches,Scalar(255,255,255));
namedWindow("surf Features1");
imshow("surf Features1",featureImage1);
namedWindow("surf Features2");
imshow("surf Features2",featureImage2);
namedWindow("匹配结果");
imshow("匹配结果",imageMatches);
waitKey(0);
}