資源簡介
基于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):?“?< std::cout?<“Number?of?SURF?points?(2):?“?<
//?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:?“?<riptors1.rows?<“?by?“?<riptors1.cols?<
//?Construction?of?the?matcher?
cv::BruteForceMatcher?>?matcher;
//?Match?the?two?image?descriptors
std::vector?matches;
matcher.match(descriptors1descriptors2?matches);
std::cout?<“Number?of?matched?points:?“?<
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
- 上一篇:基于單片機的曼徹斯特編碼程序
- 下一篇:實現8個LED流水燈匯編語言程
評論
共有 條評論