OpenCV
Keypoint matching - OpenCV 키포인트 매칭
J-sean
2019. 11. 2. 23:48
반응형
Keypoint matching.
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 45 46 | #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat trg = imread("Target.jpg", IMREAD_GRAYSCALE); Mat src = imread("Source.jpg", IMREAD_GRAYSCALE); if (trg.empty() || src.empty()) { cerr << "Image load failed!" << endl; return -1; } Ptr<Feature2D> feature = ORB::create(); vector<KeyPoint> trgKeypoints, srcKeypoints; Mat trgDesc, srcDesc; feature->detectAndCompute(trg, Mat(), trgKeypoints, trgDesc); feature->detectAndCompute(src, Mat(), srcKeypoints, srcDesc); // Detects keypoints and computes the descriptors. Ptr<DescriptorMatcher> matcher = BFMatcher::create(NORM_HAMMING); // Brute-force matcher create method. vector<DMatch> matches; // Class for matching keypoint descriptors. matcher->match(trgDesc, srcDesc, matches); // Finds the best match for each descriptor from a query set. sort(matches.begin(), matches.end()); vector<DMatch> good_matches(matches.begin(), matches.begin() + 100); Mat dst; drawMatches(trg, trgKeypoints, src, srcKeypoints, good_matches, dst, Scalar::all(-1), Scalar(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); // Draws the found matches of keypoints from two images. imshow("dst", dst); waitKey(); return 0; } |
100 best matches.
반응형