Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improve matching accuracy of cvMatchShapes in OpenCV

I tried using cvMatchShapes() to match two marker patterns. As you can see at Best way to count number of "White Blobs" in a Thresholded IplImage in OpenCV 2.3.0 , the source is having a poor image quality.

I'm not satisfied with the results returned from that function, most of the times it gives incorrect matches. How to use this function (or some suitable function) to do effective matching?

Note: My fallback solution is to change marker pattern to have fairly big/clearly visible shapes. Please visit the above link to see my current marker pattern.

EDIT

I found this comprehensive comparison of various feature detection algorithms implemented in OpenCV. http://computer-vision-talks.com/2011/01/comparison-of-the-opencvs-feature-detection-algorithms-2 . According to that FAST seems to be a good choice.

I'd give +1 to anyone who can share a good tutorial for implementing FAST (else STAR/ SURF/ SIFT) in OpenCV. I'm unable to google thinks fast as in speed :(

like image 475
coder9 Avatar asked Nov 24 '11 23:11

coder9


1 Answers

Here is the FAST inventor's website. FAST stands for Features from Accelerated Segment Test. Here is a short Wikipedia entry on AST based algorithms. Also, here is a good survey of the different feature detectors currently in use today.

FAST is actually already implemented by OpenCV if you would like to use their implementation.

EDIT : Here is short example I created to show you how to use the FAST detector:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
    Mat far = imread("far.jpg", 0);
    Mat near = imread("near.jpg", 0);

    Ptr<FeatureDetector> detector = FeatureDetector::create("FAST");

    vector<KeyPoint> farPoints;
    detector->detect(far, farPoints);

    Mat farColor;
    cvtColor(far, farColor, CV_GRAY2BGR);
    drawKeypoints(farColor, farPoints, farColor, Scalar(255, 0, 0), DrawMatchesFlags::DRAW_OVER_OUTIMG);
    imshow("farColor", farColor);
    imwrite("farPoints.jpg", farColor);

    vector<KeyPoint> nearPoints;
    detector->detect(near, nearPoints);

    Mat nearColor;
    cvtColor(near, nearColor, CV_GRAY2BGR);
    drawKeypoints(nearColor, nearPoints, nearColor, Scalar(0, 255, 0), DrawMatchesFlags::DRAW_OVER_OUTIMG);
    imshow("nearColor", nearColor);
    imwrite("nearPoints.jpg", nearColor);

    waitKey();
    return 0;
}

This code finds the follow feature points for the far and near imagery:
near imagefar image

As you can see, the near image has many more features, but it looks like the same basic structure is detected with the far image. So, you should be able to match these. Have a look at the descriptor_extractor_matcher.cpp. That should get you started.

Hope that helps!

like image 120
mevatron Avatar answered Nov 15 '22 11:11

mevatron