opencv用c还是python好得_使用OpenCV通过Python和C ++计算基本矩阵的结果不同

#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<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值