OpenCV图像匹配算法之orb
2018-07-20 来源:open-open
//orb.cpp #include "stdafx.h" #include <cv.hpp> #include <highgui.h> #include "utils.h" #include <iostream> using namespace std; void orb(char* path1, char* path2, INFO& info, bool show) { double t1,t2; t1=cvGetTickCount(); initModule_nonfree(); Mat img1, img2; img1=imread(path1,0); img2=imread(path2,0); if(img1.data==NULL) { cout<<"The image can not been loaded: "<<path1<<endl; system("pause"); exit(-1); } if(img2.data==NULL) { cout<<"The image can not been loaded: "<<path2<<endl; system("pause"); exit(-1); } Ptr<OrbFeatureDetector> orb_detector; Ptr<DescriptorExtractor> orb_descriptor; vector<KeyPoint> kpts1_orb, kpts2_orb; Mat desc1_orb, desc2_orb; Ptr<cv::DescriptorMatcher> matcher_l1 = DescriptorMatcher::create("BruteForce-Hamming"); //二进制汉明距离匹配 vector<Point2f> matches_orb, inliers_orb; vector<vector<DMatch> > dmatches_orb; orb_detector = new cv::OrbFeatureDetector(ORB_MAX_KPTS,ORB_SCALE_FACTOR,ORB_PYRAMID_LEVELS, ORB_EDGE_THRESHOLD,ORB_FIRST_PYRAMID_LEVEL,ORB_WTA_K,ORB_PATCH_SIZE); orb_descriptor = new cv::OrbDescriptorExtractor(); orb_detector->detect(img1,kpts1_orb); orb_detector->detect(img2,kpts2_orb); info.n1 = kpts1_orb.size(); info.n2 = kpts2_orb.size(); orb_descriptor->compute(img1,kpts1_orb,desc1_orb); orb_descriptor->compute(img2,kpts2_orb,desc2_orb); matcher_l1->knnMatch(desc1_orb,desc2_orb,dmatches_orb,2); matches2points_nndr(kpts1_orb,kpts2_orb,dmatches_orb,matches_orb,DRATIO); info.m=matches_orb.size()/2; compute_inliers_ransac(matches_orb,inliers_orb,MIN_H_ERROR,false); info.rm=inliers_orb.size()/2; t2=cvGetTickCount(); info.t=(t2-t1)/1000000.0/cvGetTickFrequency(); Mat img1_rgb_orb = imread(path1,1); Mat img2_rgb_orb = imread(path2,1); Mat img_com_orb = Mat(Size(img1.cols*2,img1.rows),CV_8UC3); if(show == true) { draw_inliers(img1_rgb_orb,img2_rgb_orb,img_com_orb,inliers_orb,2); imshow("orb",img_com_orb); waitKey(0); } return; }
使用
INFO orb_info; orb(path1,path2,orb_info,false); showInfo(orb_info);
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:php智能分页类代码
下一篇:php多张图片拼接成一张图片
最新资讯
热门推荐