您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > CUDA-ORB-OpenCV-图像匹配例子
#includeiostream#includeopencv2/opencv.hpp#includeopencv2/core/core.hpp#includeopencv2/cudabgsegm.hpp#includeopencv2/core/cuda.hpp#includeopencv2/highgui/highgui.hpp#includeopencv2/core/cuda_stream_accessor.hpp#includeopencv2/cudafeatures2d.hpp#includeopencv2/features2d.hppusingnamespacestd;usingnamespacecv;usingnamespacecv::cuda;intmain(){//这两张图可以在OpenCV源代码文件夹路径://..\sources\samples\gpu下找到MatsrcL0=imread(aloeL.jpg);MatsrcR0=imread(aloeR.jpg);MatsrcLg,srcRg,srcL1,srcR1;Matimg_matches;resize(srcL0,srcL1,Size(704,576));resize(srcR0,srcR1,Size(704,576));cvtColor(srcL1,srcLg,COLOR_BGR2GRAY);cvtColor(srcR1,srcRg,COLOR_BGR2GRAY);cuda::ORB_CUDAd_orbL,d_orbR;cuda::GpuMatd_srcL,d_srcR;d_srcL.upload(srcLg);d_srcR.upload(srcRg);cuda::GpuMatd_keypointsL,d_keypointsR;cuda::GpuMatd_descriptorsL,d_descriptorsR,d_descriptorsL_32F,d_descriptorsR_32F;vectorKeyPointkeyPoints_1,keyPoints_2;cuda::BFMatcher_CUDAd_matcher(NORM_L2);std::vectorDMatchmatches;std::vectorDMatchgood_matches;GpuMattrainIdx,distance;d_orbL(d_srcL,cuda::GpuMat(),d_keypointsL,d_descriptorsL);d_orbL.downloadKeyPoints(d_keypointsL,keyPoints_1);d_descriptorsL.convertTo(d_descriptorsL_32F,CV_32F);d_orbR(d_srcR,cuda::GpuMat(),d_keypointsR,d_descriptorsR);d_orbR.downloadKeyPoints(d_keypointsR,keyPoints_2);d_descriptorsR.convertTo(d_descriptorsR_32F,CV_32F);d_matcher.matchSingle(d_descriptorsL_32F,d_descriptorsR_32F,trainIdx,distance);d_matcher.matchDownload(trainIdx,distance,matches);////////////////////////////////////////////////////////////////////////////重复一遍,计算ORBBFmatch的准确时间(排除GPU内存开辟时间)int64start,end;doubletime;start=getTickCount();d_orbL(d_srcL,cuda::GpuMat(),d_keypointsL,d_descriptorsL);d_orbL.downloadKeyPoints(d_keypointsL,keyPoints_1);d_descriptorsL.convertTo(d_descriptorsL_32F,CV_32F);d_orbR(d_srcR,cuda::GpuMat(),d_keypointsR,d_descriptorsR);d_orbR.downloadKeyPoints(d_keypointsR,keyPoints_2);d_descriptorsR.convertTo(d_descriptorsR_32F,CV_32F);d_matcher.matchSingle(d_descriptorsL_32F,d_descriptorsR_32F,trainIdx,distance);d_matcher.matchDownload(trainIdx,distance,matches);intsz=matches.size();doublemax_dist=0;doublemin_dist=100;for(inti=0;isz;i++){doubledist=matches[i].distance;if(distmin_dist)min_dist=dist;if(distmax_dist)max_dist=dist;}cout\n--Maxdist:max_distendl;cout\n--Mindist:min_distendl;for(inti=0;isz;i++){if(matches[i].distance0.6*max_dist){good_matches.push_back(matches[i]);}}end=getTickCount();time=(double)(end-start)*1000/getTickFrequency();cout\nCUDAORBBFmatchtime:timemsendl;//GTX650TIBOOST显卡用时:52.27ms,大家可以作为参考drawMatches(srcL1,keyPoints_1,srcR1,keyPoints_2,good_matches,img_matches,Scalar(255,0,0),Scalar(0,255,0),vectorchar(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);imshow(Match,img_matches);waitKey();return0;}
本文标题:CUDA-ORB-OpenCV-图像匹配例子
链接地址:https://www.777doc.com/doc-6498954 .html