OpenCV, feature matching with code from the tutorial

前端 未结 1 450
滥情空心
滥情空心 2021-02-14 11:28

I copied the code of the Feature Matching with FLANN from the OpenCV tutorial page, and made the following changes:

  • I used the SIFT features, instead of SURF;
1条回答
  •  清歌不尽
    2021-02-14 12:09

    Checkout the matcher_simple.cpp example. It uses a brute force matcher that seems to work pretty well. Here is the code:

    // detecting keypoints
    SurfFeatureDetector detector(400);
    vector keypoints1, keypoints2;
    detector.detect(img1, keypoints1);
    detector.detect(img2, keypoints2);
    
    // computing descriptors
    SurfDescriptorExtractor extractor;
    Mat descriptors1, descriptors2;
    extractor.compute(img1, keypoints1, descriptors1);
    extractor.compute(img2, keypoints2, descriptors2);
    
    // matching descriptors
    BFMatcher matcher(NORM_L2);
    vector matches;
    matcher.match(descriptors1, descriptors2, matches);
    
    // drawing the results
    namedWindow("matches", 1);
    Mat img_matches;
    drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
    imshow("matches", img_matches);
    waitKey(0);
    

    0 讨论(0)
提交回复
热议问题