Ask Your Question
0

Features are not matched correctly using descriptor extractor

asked 2015-03-29 10:04:32 -0600

RB gravatar image

i wrote the below code to make features detections of two images, they are shown below. the problem is despite i ahve two different images, the output Mat object of the descriptorExtractor is full of matched features with lines so much that i cant see the image..and as they are twoo different images i expected to see some few matched features..

please have alook at my code belwo and letm ke know what i am doing wrong or what i am missing.

Image1:

pic1

Image2:

pic2

Output of descriptorExtractor:

output

Code:

 public class FeaturesMatch {

static final String path_jf01 = "C:/private/ArbeitsOrdner_19_Mar_2015/Images/FeaturesDetection/jf00.jpg";
static final String path_jf01_rev = "C:/private/ArbeitsOrdner_19_Mar_2015/Images/FeaturesDetection/jf01.jpg";
static final String path_jf01_DetectedOutPut = "C:/private/ArbeitsOrdner_19_Mar_2015/Images/FeaturesDetection/jf01_DetectedOutPut.jpg";
static final String path_jf01_rev_DetectedOutPut = "C:/private/ArbeitsOrdner_19_Mar_2015/Images/FeaturesDetection/jf01_rev_DetectedOutPut.jpg";
static final String path_jf01_Matches = "C:/private/ArbeitsOrdner_19_Mar_2015/Images/FeaturesDetection/jf01_matches.jpg";
static final String path_jf01_DrawnMatches = "C:/private/ArbeitsOrdner_19_Mar_2015/Images/FeaturesDetection/jf01_DrawnMatches.jpg";

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

                                /*Feature Detection*/
    FeatureDetector fDetect =  FeatureDetector.create(FeatureDetector.SIFT);

    MatOfKeyPoint matKeyPts_jf01 = new MatOfKeyPoint();
    fDetect.detect(path2Mat(path_jf01), matKeyPts_jf01);
    System.out.println("matKeyPts_jf01.size: " + matKeyPts_jf01.size());

    MatOfKeyPoint matKeyPts_jf01_rev = new MatOfKeyPoint();
    fDetect.detect(path2Mat(path_jf01_rev), matKeyPts_jf01_rev);
    System.out.println("matKeyPts_jf01_rev.size: " + matKeyPts_jf01_rev.size());

    Mat mat_jf01_OutPut = new Mat();
    Features2d.drawKeypoints(path2Mat(path_jf01), matKeyPts_jf01, mat_jf01_OutPut);
    Highgui.imwrite(path_jf01_DetectedOutPut, mat_jf01_OutPut);

    Mat mat_jf0_rev_OutPut = new Mat();
    Features2d.drawKeypoints(path2Mat(path_jf01_rev), matKeyPts_jf01, mat_jf0_rev_OutPut);
    Highgui.imwrite(path_jf01_rev_DetectedOutPut, mat_jf0_rev_OutPut);

                                /*DescriptorExtractor*/
    DescriptorExtractor descExtract = DescriptorExtractor.create(DescriptorExtractor.SIFT);
    Mat mat_jf01_Descriptor = new Mat();
    descExtract.compute(path2Mat(path_jf01), matKeyPts_jf01, mat_jf01_Descriptor);
    System.out.println("mat_jf01_Descriptor.size: " + mat_jf01_Descriptor.size());

    Mat mat_jf01_rev_Descriptor = new Mat();
    descExtract.compute(path2Mat(path_jf01_rev), matKeyPts_jf01_rev, mat_jf01_rev_Descriptor);

                                /*DescriptorMatcher*/
    MatOfDMatch matDMatch = new MatOfDMatch();
    DescriptorMatcher descripMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
    descripMatcher.match(mat_jf01_Descriptor, mat_jf01_rev_Descriptor, matDMatch);//is queryDescriptor = mat_jf01_Descriptor
                                                                                       //what is trainDescriptor
    Highgui.imwrite(path_jf01_Matches, matDMatch);
    System.out.println("matDMatch.size: " + matDMatch.size());
    System.out.println("matDMatch.dim: " + matDMatch.dims());
    System.out.println("matDMatch.elemSize: " + matDMatch.elemSize());
    System.out.println("matDMatch.elemSize1: " + matDMatch.elemSize1());
    System.out.println("matDMatch.hight: " + matDMatch.height());
    System.out.println("matDMatch.width: " + matDMatch.width());
    System.out.println("matDMatch.total: " + matDMatch.total());

    System.out.println("matKeyPts_jf01.size: " + matKeyPts_jf01.size());
    System.out.println("matKeyPts_jf01.dim: " + matKeyPts_jf01.dims());
    System.out.println("matKeyPts_jf01.elemSize: " + matKeyPts_jf01.elemSize());
    System.out.println("matKeyPts_jf01.elemSize1: " + matKeyPts_jf01.elemSize1());
    System.out.println("matKeyPts_jf01.hight: " + matKeyPts_jf01.height());
    System.out.println("matKeyPts_jf01.width: " + matKeyPts_jf01.width());
    System.out.println("matKeyPts_jf01.total: " + matKeyPts_jf01.total());

                                /*Draw Matches*/
    Mat mat_jf01_DrawnMatches = new Mat();
    Features2d.drawMatches(path2Mat(path_jf01), matKeyPts_jf01, path2Mat(path_jf01_rev), matKeyPts_jf01_rev, matDMatch, mat_jf01_DrawnMatches);
    Highgui.imwrite(path_jf01_DrawnMatches, mat_jf01_DrawnMatches);
}

private static Mat path2Mat(String path2File) {
    // TODO Auto-generated method stub
    return Highgui.imread(path2File);
}

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-03-29 12:52:49 -0600

Eduardo gravatar image

What you did until now is to match one set of keypoints with another set of keypoints (see my previous answer).

It means that for one keypoints, it will find the closest keypoint in the other image in term of descriptor distance, no matter if the two considered image are completly different.

To eliminate the false matches, you have to use a filtering strategie:

  • keep only pair of keypoints whose the descriptor distance is below a specific threshold,
  • keep only pair of keypoints whose the ratio between the two best matches are below a specific threshold,
  • etc.

An example of the result after a filtering: image description

Finally, take a look at this tutorial, it is for Python but it is the concept which is important.

edit flag offensive delete link more

Comments

@Eduardo ...can u please tell if there is any way to count the the lines that link the matchted features in the two images?

RB gravatar imageRB ( 2015-03-30 03:29:03 -0600 )edit
1

If you want to count the number of matches, I suppose you can get the size here: http://docs.opencv.org/java/org/opencv/core/MatOfDMatch.html.

Eduardo gravatar imageEduardo ( 2015-03-30 03:58:32 -0600 )edit

@Eduardo i have a question please, -if i took the matches from the .match(..,..,..) method, and convert them to DMatch object, and then sorted them ascendingly with respect to the distance attribute, at this case, do i need thresholding?? i am asking this question because, since i have an ascendingly sorted list, then i can just pick the top 10, 30 or whatever i want, so do i still need thresholding? i asked this question here: http://answers.opencv.org/question/59...

RB gravatar imageRB ( 2015-04-09 10:37:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-03-29 10:04:32 -0600

Seen: 525 times

Last updated: Mar 29 '15