OpenCV中ORB实时匹配

来源:互联网 发布:vr unity3d 比ue4清晰 编辑:程序博客网 时间:2024/06/08 15:09
// SIFT跟踪
#include "StdAfx.h"#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/features2d/features2d.hpp>using namespace cv;int main(int argc, char** argv) { CvCapture* capture = cvCreateCameraCapture(0);IplImage* frame;while (1){frame = cvQueryFrame(capture);Mat img_1 = imread("C:\\Users\\lijunliang\\Desktop\\book.png"); Mat img_2(frame);  // -- Step 1: Detect the keypoints using STAR Detector std::vector<KeyPoint> keypoints_1,keypoints_2; ORB orb; orb.detect(img_1, keypoints_1); orb.detect(img_2, keypoints_2);// -- Stpe 2: Calculate descriptors (feature vectors) Mat descriptors_1, descriptors_2; orb.compute(img_1, keypoints_1, descriptors_1); orb.compute(img_2, keypoints_2, descriptors_2);//-- Step 3: Matching descriptor vectors with a brute force matcher BFMatcher matcher(NORM_HAMMING); std::vector<DMatch> mathces; matcher.match(descriptors_1, descriptors_2, mathces); // -- dwaw matches Mat img_mathes; drawMatches(img_1, keypoints_1, img_2, keypoints_2, mathces, img_mathes); // -- show imshow("Mathces", img_mathes);waitKey(1);     }cvReleaseCapture(&capture);cvDestroyWindow("Mathces");      return 0; }


二、结果


原创粉丝点击