资源简介
用opencv实现特征点的检测与匹配
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main()
{
// Read input images
cv::Mat image1= cv::imread(“OpticalFlow0.jpg“0);
cv::Mat image2= cv::imread(“OpticalFlow1.jpg“0);
if (!image1.data || !image2.data)
return 0;
// Display the images
cv::namedWindow(“Right Image“);
cv::imshow(“Right Image“image1);
cv::namedWindow(“Left Image“);
cv::imshow(“Left Image“image2);
// vector of keypoints
std::vector keypoints1;
std::vector keypoints2;
// Construction of the SURF feature detector
cv::SurfFeatureDetector surf(3000);
// Detection of the SURF features
surf.detect(image1keypoints1);
surf.detect(image2keypoints2);
std::cout << “Number of SURF points (1): “ << keypoints1.size() << std::endl;
std::cout << “Number of SURF points (2): “ << keypoints2.size() << std::endl;
// Draw the kepoints
cv::Mat imageKP;
cv::drawKeypoints(image1keypoints1imageKPcv::Scalar(255255255)cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
cv::namedWindow(“Right SURF Features“);
cv::imshow(“Right SURF Features“imageKP);
cv::drawKeypoints(image2keypoints2imageKPcv::Scalar(255255255)cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
cv::namedWindow(“Left SURF Features“);
cv::imshow(“Left SURF Features“imageKP);
// Construction of the SURF descriptor extractor
cv::SurfDescriptorExtractor surfDesc;
// Extraction of the SURF descriptors
cv::Mat descriptors1 descriptors2;
surfDesc.compute(image1keypoints1descriptors1);
surfDesc.compute(image2keypoints2descriptors2);
std::cout << “descriptor matrix size: “ << descriptors1.rows << “ by “ << descriptors1.cols << std::endl;
// Construction of the matcher
cv::BruteForceMatcher< cv::L2 > matcher;
// Match the two image descriptors
std::vector matches;
matcher.match(descriptors1descriptors2 matches);
std::cout << “Number of matched points: “ << matches.size() << std::endl;
std::nth_element(matches.begin() // initial position
matches.begin()+24 // position of the sorted element
matches.end()); // end position
// remove all elements after the 25th
matches.erase(matches.begin()+25 matches.end());
cv::Mat imageMatches;
cv::drawMatches(image1keypoints1 // 1st image and its keypoints
image2keypoints2 // 2nd image and its keypoints
matches // the matches
imageMatches // the image produced
cv::Scalar(255255255)); // color of the lines
cv::namedWindow(“Matches“);
cv::imshow(“Matches“imageMatches);
cv::waitKey();
return 0;
int size=7;
cv::Mat imaf1;
image1.convertTo(imaf1CV_32F);
cv::
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-01-06 13:25 HW3\
文件 3080 2013-01-04 20:40 HW3\tracking.cpp
文件 124031 2011-01-17 05:45 HW3\church01.jpg
文件 48594 2013-01-04 20:41 HW3\tracking
文件 120223 2008-10-07 17:00 HW3\OpticalFlow1.jpg
文件 115 2013-01-04 19:44 HW3\README
文件 124874 2011-01-17 05:47 HW3\church02.jpg
文件 123322 2008-10-07 17:00 HW3\OpticalFlow0.jpg
- 上一篇:基于LPC2366的LCD12864-5液晶驱动程序
- 下一篇:ATM系统UML建模
评论
共有 条评论