#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<
opencv用c还是python好得_使用OpenCV通过Python和C ++计算基本矩阵的结果不同
最新推荐文章于 2023-05-27 14:15:00 发布