1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include <iostream> #include <vector> #include <opencv2/opencv.hpp> using namespace std; using namespace cv;
int main(){ Mat box = imread("./data/box.png"); Mat box_in_scene = imread("./data/box_in_scene.png"); imshow("box",box); imshow("box_in_scene",box_in_scene);
vector<KeyPoint> keypoints1,keypoints2; Mat descriptors1,descriptors2; Ptr<Feature2D> orb = ORB::create(); orb->detectAndCompute(box,Mat(),keypoints1,descriptors1,false); orb->detectAndCompute(box_in_scene,Mat(),keypoints2,descriptors2,false);
BFMatcher matcher(NORM_HAMMING,true); vector<DMatch> matches; matcher.match(descriptors1,descriptors2,matches);
int maxdist = 0; vector<DMatch> goodMtachs;
Mat result ; drawMatches(box,keypoints1,box_in_scene,keypoints2,matches,result); imshow("result", result);
waitKey(0); return 0; }
|