How to link the matched features with lines

asked 2015-03-27 10:08:12 -0600

RB gravatar image

updated 2015-03-27 10:55:24 -0600

berak gravatar image

I wrote the below code as a test to have hands-on in opencv, according to the below posted code i can detect the features in an image by drawing circles around them, and now i can have a picture that shows matches of two images.

but what i could not do is, to have the matches found in the two images linked to each other through lines as shown here

which method should i use to link the similar features with line?

Code:

    public static void main(String[] args) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    Mat img_0 = Highgui.imread(PATH_0);
    Mat img_0_rev = Highgui.imread(PATH_1);
    Mat img_outCombined = new Mat();
    Mat img_0_Out = new Mat();
    Mat img_0_rev_Out = new Mat();

    FeatureDetector fDetect = FeatureDetector.create(FeatureDetector.ORB);

    MatOfKeyPoint mKeyPoints_0 = new MatOfKeyPoint();
    fDetect.detect(img_0, mKeyPoints_0);
    System.out.println("mKeyPoint_0: " + mKeyPoints_0.size());

    MatOfKeyPoint mKeyPoints_1 = new MatOfKeyPoint();
    fDetect.detect(img_0_rev, mKeyPoints_1);
    System.out.println("mKeyPoint_1: " + mKeyPoints_1.size());

    Features2d.drawKeypoints(img_0, mKeyPoints_0, img_0_Out, new Scalar(220,0,0), Features2d.DRAW_RICH_KEYPOINTS);
    Highgui.imwrite(PATH_5, img_0_Out);
    Features2d.drawKeypoints(img_0_rev, mKeyPoints_1, img_0_rev_Out, new Scalar(50, 0, 0), Features2d.DRAW_RICH_KEYPOINTS);
    Highgui.imwrite(PATH_6, img_0_rev_Out);

    MatOfDMatch mDMatch = new MatOfDMatch();
    Features2d.drawMatches(img_0, mKeyPoints_0, img_0_rev, mKeyPoints_1, mDMatch, img_outCombined);

    if (!img_outCombined.empty()) {
        if (!Highgui.imwrite(PATH_4, img_outCombined)) {
            System.out.println("write image operation failed");
        } else {
            System.out.println("");
        }
    } else {
        System.out.println("output image is empty");
    }
}
edit retag flag offensive close merge delete

Comments

2

matching part was missing, mDMatch you are passing empty.

bvbdort gravatar imagebvbdort ( 2015-03-27 11:01:55 -0600 )edit