Keypoint matching - OpenCV 키포인트 매칭
OpenCV 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.
반응형
'OpenCV' 카테고리의 다른 글
Simple copy and save in cv::imshow() 간단하게 이미지 복사, 저장 하기 (0) | 2019.11.17 |
---|---|
Finding a homography matrix - OpenCV 두 평면 사이의 투영 변환 행렬 (0) | 2019.11.03 |
Detect, compute and draw keypoints - OpenCV 키포인트 찾기 (0) | 2019.11.02 |
Screen capture - Windows API, OpenCV로 화면 캡쳐하기 (0) | 2019.10.28 |
Windows dialog-based OpenCV program 윈도우 대화상자 OpenCV 프로그램 만들기 (2) | 2019.10.26 |