#include<opencv2/opencv.hpp>
#include<iostream>
#include<vector>
using namespace cv;
using namespace std;
//SIFT的方式
using namespace std;
using namespace cv;
int main3(int* argv, int** argc)
{
Mat imgRight = imread("E:/sift_test.jpg"); //右图
Mat imgLeft = imread("E:/sift_test2.jpg"); //左图
int numfeature = 1000; //设置特征点个数
Ptr<SIFT>Detector = SIFT::create(numfeature);//取1000个特征点
//auto Detector = SIFT::create(); //自动生成特征点的个数
vector<KeyPoint> kpCat, kpSmallCat;
Mat descriptorCat, descriptorSmallCat;
Detector->detectAndCompute(imgRight, Mat(), kpCat, descriptorCat);
printf("检测到的左图所有的特征点个数:%d", kpCat.size()); //打印检测到的特征点个数
Detector->detectAndCompute(imgLeft, Mat(), kpSmallCat, descriptorSmallCat);
printf("检测到的右图所有的特征点个数:%d", kpCat.size()); //打印检测到的特征点个数
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);
std::vector<DMatch> matchers;
matcher->match(descriptorCat, descriptorSmallCat, matchers);
Mat imgMatches;
drawMatches(imgRight, kpCat, imgLeft, kpSmallCat, matchers, imgMatches); //将右图和左图的特征点匹配并画出。
//drawMatches(imgRight, kpCat, imgLeft, kpSmallCat, matchers, imgMatches, Scalar(0, 255, 0));//将右图和左图的特征点匹配并指定用绿色线画出。
//imshow("左图", imgRight);
//imshow("右图", imgLeft);
namedWindow("特征点匹配图", CV_WINDOW_NORMAL); //可任意改变窗口大小
imshow("特征点匹配图", imgMatches);
imwrite("./效果图/特征点匹配图.jpg", imgMatches);
waitKey(0);
return true;
}
05-16
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交