Skip to content

Instantly share code, notes, and snippets.

@lecram
Created February 21, 2014 19:00
Show Gist options
  • Select an option

  • Save lecram/9140902 to your computer and use it in GitHub Desktop.

Select an option

Save lecram/9140902 to your computer and use it in GitHub Desktop.

Revisions

  1. lecram created this gist Feb 21, 2014.
    44 changes: 44 additions & 0 deletions keyp.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    /* g++ -o keyp `pkg-config --libs opencv` keyp.cpp */

    #include <iostream>
    #include <vector>

    #include "opencv2/opencv.hpp"

    using namespace std;
    using namespace cv;

    int main(int argc, char *argv[])
    {
    if (argc != 3) {
    cout << "usage:" << endl << argv[0] << " image1 image2" << endl;
    return 1;
    }
    Mat img1, img2, img3;
    vector<KeyPoint> keyps1, keyps2;
    Mat descs1, descs2;
    vector<DMatch> matches;
    Ptr<FeatureDetector> fd;
    Ptr<DescriptorExtractor> de;
    Ptr<DescriptorMatcher> dm;
    img1 = imread(argv[1]);
    img2 = imread(argv[2]);
    //cvtColor(img1, img1, CV_BGR2GRAY);
    //cvtColor(img2, img2, CV_BGR2GRAY);

    // FAST, STAR, SIFT, SURF, ORB, BRISK, MSER, GFTT, HARRIS, Dense, SimpleBlob
    fd = FeatureDetector::create("SIFT");
    fd->detect(img1, keyps1);
    fd->detect(img2, keyps2);

    // SIFT, SURF, BRIEF, BRISK, ORB, FREAK
    de = DescriptorExtractor::create("SIFT");
    de->compute(img1, keyps1, descs1);
    de->compute(img2, keyps2, descs2);

    // BruteForce, BruteForce-L1, BruteForce-Hamming, BruteForce-Hamming(2), FlannBased
    dm = DescriptorMatcher::create("FlannBased");
    dm->match(descs1, descs2, matches);
    cout << matches.size() << endl;
    return 0;
    }