Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Features are not matched correctly using descriptor extractor

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);
}

}