#include#include#include#include#include#include#include#include#includeusingnamespacestd;intmain(intargc,char*argv[]){//Define intrinsic matrixcv::Matintrinsic=(cv::Mat_(3,3)<<522.4825,0,300.9989,0,522.5723,258.1389,0,0,1);// Read input imagesstringjpg1=argv[1];jpg1.append(".jpg");stringjpg2=argv[2];jpg2.append(".jpg");cv::Matimage1=cv::imread(jpg1,0);cv::Matimage2=cv::imread(jpg2,0);if(!image1.data||!image2.data)return0;// Display the images// cv::namedWindow("Image 1");// cv::imshow("Image 1",image1);// cv::namedWindow("Image 2");// cv::imshow("Image 2",image2);// pointer to the feature point detector objectcv::Ptr<:featuredetector>detector=newcv::SurfFeatureDetector();// pointer to the feature descriptor extractor objectcv::Ptr<:descriptorextractor>extractor=newcv::SurfDescriptorExtractor();// Detection of the SURF featuresvector<:keypoint>keypoints1,keypoints2;detector->detect(image1,keypoints1);detector->detect(image2,keypoints2);// Extraction of the SURF descriptorscv::Matdescriptors1,descriptors2;extractor->compute(image1,keypoints1,descriptors1);extractor->compute(image2,keypoints2,descriptors2);// Construction of the matchercv::BruteForceMatcher<:l2>>matcher;vector>matches;vector<:dmatch>good_matches;matcher.knnMatch(descriptors1,descriptors2,matches,2);for(vector>::iterator matchIterator=matches.begin();matchIterator!=matches.end();++matchIterator){if((*matchIterator)[0].distance<0.7f*(*matchIterator)[1].distance){good_matches.push_back((*matchIterator)[0]);}}// Convert keypoints into Point2fvector<:point2f>src_pts,dst_pts;for(vector<:dmatch>::iterator it=good_matches.begin();it!=good_matches.end();++it){// Get the position of left keypointsfloatx=keypoints1[it->queryIdx].pt.x;floaty=keypoints1[it->queryIdx].pt.y;src_pts.push_back(cv::Point2f(x,y));// Get the position of right keypointsx=keypoints2[it->trainIdx].pt.x;y=keypoints2[it->trainIdx].pt.y;dst_pts.push_back(cv::Point2f(x,y));}// Compute F matrix using RANSACcv::Matfundemental=cv::findFundamentalMat(cv::Mat(src_pts),cv::Mat(dst_pts),// matching pointsCV_FM_RANSAC,// RANSAC method5.0);// distancecout<

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐