Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Keypoint matcher matches all keypoints from train to query irrespective of the scene?

I am using feature detection to recognize known object inn a real time camera frame with android but matcher shows every keypoint from the object image is matched to the keypoints in the scene/camera frame.

the logcat outputs the keypoint and matched info

08-07 01:40:13.899: I/OCVSample::Activity(26175): mGray H/W  : 320x240
08-07 01:40:13.899: I/OCVSample::Activity(26175): mRef H/W  : 153x94
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypoints H/W  : 1x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypointsRef H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptor Size: 32x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptorRef Size : 32x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): Matches Size: 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): matchesList Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): LIST D MATCH -- Max dist : 97.0 -- Min dist : 67.0
08-07 01:40:13.899: I/OCVSample::Activity(26175): good_matches Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches   : Mat [ 33*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x6761d8, dataAddr=0x8bef80 ]

the code is

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);

detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);

extractor.compute(mGray, keypoints, descriptor);
extractor.compute(mRef, keypointsRef, descriptorRef);

matcher.match(descriptorRef, descriptor, matchs);

List<DMatch> matchesList = matchs.toList();
    Double max_dist = 0.0;
    Double min_dist = 100.0;

    for (int i = 0; i < matchesList.size(); i++) {
        Double dist = (double) matchesList.get(i).distance;
        if (dist < min_dist)
            min_dist = dist;
        if (dist > max_dist)
            max_dist = dist;
    }


    LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
    MatOfDMatch gm = new MatOfDMatch(); 

    for (int i = 0; i < matchesList.size(); i++) {
        if (matchesList.get(i).distance <= (3 * min_dist)) {
                good_matches.addLast(matchesList.get(i));
            }
    }

    gm.fromList(good_matches);          
  Log.i(TAG, "gm from good_matches Size: " + gm.size());

what is the problem with matcher.

click to hide/show revision 2
Error after changes added at bottom.

Keypoint matcher matches all keypoints from train to query irrespective of the scene?

I am using feature detection to recognize known object inn a real time camera frame with android but matcher shows every keypoint from the object image is matched to the keypoints in the scene/camera frame.

the logcat outputs the keypoint and matched info

08-07 01:40:13.899: I/OCVSample::Activity(26175): mGray H/W  : 320x240
08-07 01:40:13.899: I/OCVSample::Activity(26175): mRef H/W  : 153x94
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypoints H/W  : 1x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypointsRef H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptor Size: 32x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptorRef Size : 32x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): Matches Size: 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): matchesList Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): LIST D MATCH -- Max dist : 97.0 -- Min dist : 67.0
08-07 01:40:13.899: I/OCVSample::Activity(26175): good_matches Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches   : Mat [ 33*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x6761d8, dataAddr=0x8bef80 ]

the code is

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);

detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);

extractor.compute(mGray, keypoints, descriptor);
extractor.compute(mRef, keypointsRef, descriptorRef);

matcher.match(descriptorRef, descriptor, matchs);

List<DMatch> matchesList = matchs.toList();
    Double max_dist = 0.0;
    Double min_dist = 100.0;

    for (int i = 0; i < matchesList.size(); i++) {
        Double dist = (double) matchesList.get(i).distance;
        if (dist < min_dist)
            min_dist = dist;
        if (dist > max_dist)
            max_dist = dist;
    }


    LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
    MatOfDMatch gm = new MatOfDMatch(); 

    for (int i = 0; i < matchesList.size(); i++) {
        if (matchesList.get(i).distance <= (3 * min_dist)) {
                good_matches.addLast(matchesList.get(i));
            }
    }

    gm.fromList(good_matches);          
  Log.i(TAG, "gm from good_matches Size: " + gm.size());

what is the problem with matcher.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ UPDATE /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

OK now I use

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

I now get good-matches less than all reference keypoints depending on condition

  if (matchesList.get(i).distance <= (3 * min_dist)) {
 good_matches.addLast(matchesList.get(i));
}

THE logcat now is

Keypoints Size: 1x676 
KeypointsRef Size : 1x139
descriptor Size: 32x629
descriptorRef Size : 32x32
Matches Size: 1x32
matchesList Size: 32
LIST D MATCH -- Max dist : 447.1934814453125 -- Min dist : 100.0
good matches size: 5
gm from good_matches Size: 1x5
obj Size: 1x5
scene Size: 1x5

A few output samples

Frame - 1

Calib3d.findHomography  hg Size: 3x3
hg : [-1.946750073879795, -2.153719667711051, 161.7932939049003;
      -2.245372221173412, -2.194859343368184, 175.7583814286593;
      -0.01283591450941816, -0.01266823891952267, 0.9999999999999999]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [161.79329, 175.75838; 141.15591, 174.06831; 157.10199, 173.61986; 213.06747, 160.14717]

Frame-2

hg : [-1.934167716139827, -4.236308808871488, 249.7027233816234;
      -0.8409584670694304, -1.643347407920087, 101.4526716763755;
      -0.007981402185299564, -0.01677063017280203, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [249.70273, 101.45267; 209.01646, 123.05411; 247.24049, 101.07324; 257.63394, 91.981918]

Frame-3

hg : [18.44625165513222, -30.49302758685548, 245.9935488915967;
       8.983047514459511, -15.26849377435921, 134.9835860140666;
       0.07275391289238894, -0.1212195797795232, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [245.99355, 134.98358; 252.92078, 124.42062; 274.09152, 100.6524; 252.08675, 125.08897]

Frame-4

hg : [2523.743444745383, -3436.790363876738, -6320.163263697045;
      1152.68745032164, -1181.519781694952, -18248.99783312392;
      10.26100642365376, -14.53251070681075, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [-6320.1631, -18248.998; 241.77501, 100.64852; 277.01508, 229.64558; 241.293, 94.730072]

the "obj_corners is equal to the reference image dimensions(153*94)"

but the "scene_corners is either negative or random and mostly all points are almost at the same location".

Is the find homography hg value correct it is sometimes negative? Is the error with findHomography or perspectiveTransform.

Keypoint matcher matches all keypoints from train to query irrespective of the scene?

I am using feature detection to recognize known object inn a real time camera frame with android but matcher shows every keypoint from the object image is matched to the keypoints in the scene/camera frame.

the logcat outputs the keypoint and matched info

08-07 01:40:13.899: I/OCVSample::Activity(26175): mGray H/W  : 320x240
08-07 01:40:13.899: I/OCVSample::Activity(26175): mRef H/W  : 153x94
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypoints H/W  : 1x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypointsRef H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptor Size: 32x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptorRef Size : 32x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): Matches Size: 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): matchesList Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): LIST D MATCH -- Max dist : 97.0 -- Min dist : 67.0
08-07 01:40:13.899: I/OCVSample::Activity(26175): good_matches Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches   : Mat [ 33*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x6761d8, dataAddr=0x8bef80 ]

the code is

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);

detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);

extractor.compute(mGray, keypoints, descriptor);
extractor.compute(mRef, keypointsRef, descriptorRef);

matcher.match(descriptorRef, descriptor, matchs);

List<DMatch> matchesList = matchs.toList();
    Double max_dist = 0.0;
    Double min_dist = 100.0;

    for (int i = 0; i < matchesList.size(); i++) {
        Double dist = (double) matchesList.get(i).distance;
        if (dist < min_dist)
            min_dist = dist;
        if (dist > max_dist)
            max_dist = dist;
    }


    LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
    MatOfDMatch gm = new MatOfDMatch(); 

    for (int i = 0; i < matchesList.size(); i++) {
        if (matchesList.get(i).distance <= (3 * min_dist)) {
                good_matches.addLast(matchesList.get(i));
            }
    }

    gm.fromList(good_matches);          
  Log.i(TAG, "gm from good_matches Size: " + gm.size());

what is the problem with matcher.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ UPDATE /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

OK now I use

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

I now get good-matches less than all reference keypoints depending on condition

  if (matchesList.get(i).distance <= (3 * min_dist)) {
 good_matches.addLast(matchesList.get(i));
}

THE logcat now is

Keypoints Size: 1x676 
KeypointsRef Size : 1x139
descriptor Size: 32x629
descriptorRef Size : 32x32
Matches Size: 1x32
matchesList Size: 32
LIST D MATCH -- Max dist : 447.1934814453125 -- Min dist : 100.0
good matches size: 5
gm from good_matches Size: 1x5
obj Size: 1x5
scene Size: 1x5

A few output samples

Frame - 1

Calib3d.findHomography  hg Size: 3x3
hg : [-1.946750073879795, -2.153719667711051, 161.7932939049003;
      -2.245372221173412, -2.194859343368184, 175.7583814286593;
      -0.01283591450941816, -0.01266823891952267, 0.9999999999999999]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [161.79329, 175.75838; 141.15591, 174.06831; 157.10199, 173.61986; 213.06747, 160.14717]

Frame-2

hg : [-1.934167716139827, -4.236308808871488, 249.7027233816234;
      -0.8409584670694304, -1.643347407920087, 101.4526716763755;
      -0.007981402185299564, -0.01677063017280203, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [249.70273, 101.45267; 209.01646, 123.05411; 247.24049, 101.07324; 257.63394, 91.981918]

Frame-3

hg : [18.44625165513222, -30.49302758685548, 245.9935488915967;
       8.983047514459511, -15.26849377435921, 134.9835860140666;
       0.07275391289238894, -0.1212195797795232, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [245.99355, 134.98358; 252.92078, 124.42062; 274.09152, 100.6524; 252.08675, 125.08897]

Frame-4

hg : [2523.743444745383, -3436.790363876738, -6320.163263697045;
      1152.68745032164, -1181.519781694952, -18248.99783312392;
      10.26100642365376, -14.53251070681075, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [-6320.1631, -18248.998; 241.77501, 100.64852; 277.01508, 229.64558; 241.293, 94.730072]

the "obj_corners is equal to the reference image dimensions(153*94)"

but the "scene_corners is either negative or random and mostly all points are almost at the same location".

Is the find homography hg value correct it is sometimes negative? Is the error with findHomography or perspectiveTransform.

click to hide/show revision 4
Error after changes made -added at bottom

Keypoint matcher matches all keypoints from train to query irrespective of the scene?

I am using feature detection to recognize known object inn a real time camera frame with android but matcher shows every keypoint from the object image is matched to the keypoints in the scene/camera frame.

the logcat outputs the keypoint and matched info

08-07 01:40:13.899: I/OCVSample::Activity(26175): mGray H/W  : 320x240
08-07 01:40:13.899: I/OCVSample::Activity(26175): mRef H/W  : 153x94
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypoints H/W  : 1x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypointsRef H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptor Size: 32x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptorRef Size : 32x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): Matches Size: 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): matchesList Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): LIST D MATCH -- Max dist : 97.0 -- Min dist : 67.0
08-07 01:40:13.899: I/OCVSample::Activity(26175): good_matches Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches   : Mat [ 33*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x6761d8, dataAddr=0x8bef80 ]

the code is

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);

detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);

extractor.compute(mGray, keypoints, descriptor);
extractor.compute(mRef, keypointsRef, descriptorRef);

matcher.match(descriptorRef, descriptor, matchs);

List<DMatch> matchesList = matchs.toList();
    Double max_dist = 0.0;
    Double min_dist = 100.0;

    for (int i = 0; i < matchesList.size(); i++) {
        Double dist = (double) matchesList.get(i).distance;
        if (dist < min_dist)
            min_dist = dist;
        if (dist > max_dist)
            max_dist = dist;
    }


    LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
    MatOfDMatch gm = new MatOfDMatch(); 

    for (int i = 0; i < matchesList.size(); i++) {
        if (matchesList.get(i).distance <= (3 * min_dist)) {
                good_matches.addLast(matchesList.get(i));
            }
    }

    gm.fromList(good_matches);          
  Log.i(TAG, "gm from good_matches Size: " + gm.size());

what is the problem with matcher.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ UPDATE /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

OK now I use

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

I now get good-matches less than all no of reference keypoints depending on conditioncondition below

  if (matchesList.get(i).distance <= (3 * min_dist)) {
 good_matches.addLast(matchesList.get(i));
}

THE The logcat now isshows(compare-previous)

Keypoints Size: 1x676 
KeypointsRef Size : 1x139
descriptor Size: 32x629
descriptorRef Size : 32x32
Matches Size: 1x32
matchesList Size: 32
LIST D MATCH -- Max dist : 447.1934814453125 -- Min dist : 100.0
good matches size: 5
gm from good_matches Size: 1x5
obj Size: 1x5
scene Size: 1x5
Calib3d.findHomography  hg Size: 3x3

A few output samples

Frame - 1

Calib3d.findHomography  hg Size: 3x3
hg : [-1.946750073879795, -2.153719667711051, 161.7932939049003;
      -2.245372221173412, -2.194859343368184, 175.7583814286593;
      -0.01283591450941816, -0.01266823891952267, 0.9999999999999999]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [161.79329, 175.75838; 141.15591, 174.06831; 157.10199, 173.61986; 213.06747, 160.14717]

Frame-2

hg : [-1.934167716139827, -4.236308808871488, 249.7027233816234;
      -0.8409584670694304, -1.643347407920087, 101.4526716763755;
      -0.007981402185299564, -0.01677063017280203, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [249.70273, 101.45267; 209.01646, 123.05411; 247.24049, 101.07324; 257.63394, 91.981918]

Frame-3

hg : [18.44625165513222, -30.49302758685548, 245.9935488915967;
       8.983047514459511, -15.26849377435921, 134.9835860140666;
       0.07275391289238894, -0.1212195797795232, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [245.99355, 134.98358; 252.92078, 124.42062; 274.09152, 100.6524; 252.08675, 125.08897]

Frame-4

hg : [2523.743444745383, -3436.790363876738, -6320.163263697045;
      1152.68745032164, -1181.519781694952, -18248.99783312392;
      10.26100642365376, -14.53251070681075, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [-6320.1631, -18248.998; 241.77501, 100.64852; 277.01508, 229.64558; 241.293, 94.730072]

the "obj_corners is equal to the reference image dimensions(153*94)"

but the "scene_corners is either negative or random and mostly all points are almost at the same location".

Is the find homography hg value correct it is sometimes negative? Is the error with findHomography or perspectiveTransform.

Keypoint matcher matches all keypoints from train to query irrespective of the scene?

I am using feature detection to recognize known object inn a real time camera frame with android but matcher shows every keypoint from the object image is matched to the keypoints in the scene/camera frame.

the logcat outputs the keypoint and matched info

08-07 01:40:13.899: I/OCVSample::Activity(26175): mGray H/W  : 320x240
08-07 01:40:13.899: I/OCVSample::Activity(26175): mRef H/W  : 153x94
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypoints H/W  : 1x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypointsRef H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptor Size: 32x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptorRef Size : 32x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): Matches Size: 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): matchesList Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): LIST D MATCH -- Max dist : 97.0 -- Min dist : 67.0
08-07 01:40:13.899: I/OCVSample::Activity(26175): good_matches Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches   : Mat [ 33*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x6761d8, dataAddr=0x8bef80 ]

the code is

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);

detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);

extractor.compute(mGray, keypoints, descriptor);
extractor.compute(mRef, keypointsRef, descriptorRef);

matcher.match(descriptorRef, descriptor, matchs);

List<DMatch> matchesList = matchs.toList();
    Double max_dist = 0.0;
    Double min_dist = 100.0;

    for (int i = 0; i < matchesList.size(); i++) {
        Double dist = (double) matchesList.get(i).distance;
        if (dist < min_dist)
            min_dist = dist;
        if (dist > max_dist)
            max_dist = dist;
    }


    LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
    MatOfDMatch gm = new MatOfDMatch(); 

    for (int i = 0; i < matchesList.size(); i++) {
        if (matchesList.get(i).distance <= (3 * min_dist)) {
                good_matches.addLast(matchesList.get(i));
            }
    }

    gm.fromList(good_matches);          
  Log.i(TAG, "gm from good_matches Size: " + gm.size());

what is the problem with matcher.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ UPDATE /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

OK now I use

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

I now get good-matches less than no of reference keypoints depending on condition below

  if (matchesList.get(i).distance <= (3 * min_dist)) {
 good_matches.addLast(matchesList.get(i));
}

The logcat now shows(compare-previous)

Keypoints Size: 1x676 
KeypointsRef Size : 1x139
descriptor Size: 32x629
descriptorRef Size : 32x32
Matches Size: 1x32
matchesList Size: 32
LIST D MATCH -- Max dist : 447.1934814453125 -- Min dist : 100.0
good matches size: 5
gm from good_matches Size: 1x5
obj Size: 1x5
scene Size: 1x5
Calib3d.findHomography  hg Size: 3x3

A few output samples

Frame - 1

hg : [-1.946750073879795, -2.153719667711051, 161.7932939049003;
      -2.245372221173412, -2.194859343368184, 175.7583814286593;
      -0.01283591450941816, -0.01266823891952267, 0.9999999999999999]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [161.79329, 175.75838; 141.15591, 174.06831; 157.10199, 173.61986; 213.06747, 160.14717]

Frame-2

hg : [-1.934167716139827, -4.236308808871488, 249.7027233816234;
      -0.8409584670694304, -1.643347407920087, 101.4526716763755;
      -0.007981402185299564, -0.01677063017280203, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [249.70273, 101.45267; 209.01646, 123.05411; 247.24049, 101.07324; 257.63394, 91.981918]

Frame-3

hg : [18.44625165513222, -30.49302758685548, 245.9935488915967;
       8.983047514459511, -15.26849377435921, 134.9835860140666;
       0.07275391289238894, -0.1212195797795232, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [245.99355, 134.98358; 252.92078, 124.42062; 274.09152, 100.6524; 252.08675, 125.08897]

Frame-4

hg : [2523.743444745383, -3436.790363876738, -6320.163263697045;
      1152.68745032164, -1181.519781694952, -18248.99783312392;
      10.26100642365376, -14.53251070681075, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [-6320.1631, -18248.998; 241.77501, 100.64852; 277.01508, 229.64558; 241.293, 94.730072]

the "obj_corners is equal to the reference image dimensions(153*94)"

but the "scene_corners is either negative or random and mostly all points are almost at the same location".

Is the find homography hg value correct it is sometimes negative? Is the error with findHomography or perspectiveTransform.

Keypoint matcher matches all keypoints from train to query irrespective of the scene?

I am using feature detection to recognize known object inn a real time camera frame with android but matcher shows every keypoint from the object image is matched to the keypoints in the scene/camera frame.

the logcat outputs the keypoint and matched info

08-07 01:40:13.899: I/OCVSample::Activity(26175): mGray H/W  : 320x240
08-07 01:40:13.899: I/OCVSample::Activity(26175): mRef H/W  : 153x94
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypoints H/W  : 1x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): keypointsRef H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptor Size: 32x381
08-07 01:40:13.899: I/OCVSample::Activity(26175): descriptorRef Size : 32x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): Matches Size: 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): matchesList Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): LIST D MATCH -- Max dist : 97.0 -- Min dist : 67.0
08-07 01:40:13.899: I/OCVSample::Activity(26175): good_matches Size: 33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches H/W  : 1x33
08-07 01:40:13.899: I/OCVSample::Activity(26175): gm good_matches   : Mat [ 33*1*CV_32FC4, isCont=true, isSubmat=false, nativeObj=0x6761d8, dataAddr=0x8bef80 ]

the code is

FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);

detector.detect(mGray, keypoints);
detector.detect(mRef, keypointsRef);

extractor.compute(mGray, keypoints, descriptor);
extractor.compute(mRef, keypointsRef, descriptorRef);

matcher.match(descriptorRef, descriptor, matchs);

List<DMatch> matchesList = matchs.toList();
    Double max_dist = 0.0;
    Double min_dist = 100.0;

    for (int i = 0; i < matchesList.size(); i++) {
        Double dist = (double) matchesList.get(i).distance;
        if (dist < min_dist)
            min_dist = dist;
        if (dist > max_dist)
            max_dist = dist;
    }


    LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
    MatOfDMatch gm = new MatOfDMatch(); 

    for (int i = 0; i < matchesList.size(); i++) {
        if (matchesList.get(i).distance <= (3 * min_dist)) {
                good_matches.addLast(matchesList.get(i));
            }
    }

    gm.fromList(good_matches);          
  Log.i(TAG, "gm from good_matches Size: " + gm.size());

what is the problem with matcher.

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ UPDATE /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

OK now I use

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

I now get good-matches less than no of reference keypoints depending on condition below

  if (matchesList.get(i).distance <= (3 * min_dist)) {
 good_matches.addLast(matchesList.get(i));
}

The logcat now shows(compare-previous)

Keypoints Size: 1x676 
KeypointsRef Size : 1x139
descriptor Size: 32x629
descriptorRef Size : 32x32
Matches Size: 1x32
matchesList Size: 32
LIST D MATCH -- Max dist : 447.1934814453125 -- Min dist : 100.0
good matches size: 5
gm from good_matches Size: 1x5
obj Size: 1x5
scene Size: 1x5
Calib3d.findHomography  hg Size: 3x3

A few output samples

Frame - 1

hg : [-1.946750073879795, -2.153719667711051, 161.7932939049003;
      -2.245372221173412, -2.194859343368184, 175.7583814286593;
      -0.01283591450941816, -0.01266823891952267, 0.9999999999999999]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [161.79329, 175.75838; 141.15591, 174.06831; 157.10199, 173.61986; 213.06747, 160.14717]

Frame-2

hg : [-1.934167716139827, -4.236308808871488, 249.7027233816234;
      -0.8409584670694304, -1.643347407920087, 101.4526716763755;
      -0.007981402185299564, -0.01677063017280203, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [249.70273, 101.45267; 209.01646, 123.05411; 247.24049, 101.07324; 257.63394, 91.981918]

Frame-3

hg : [18.44625165513222, -30.49302758685548, 245.9935488915967;
       8.983047514459511, -15.26849377435921, 134.9835860140666;
       0.07275391289238894, -0.1212195797795232, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [245.99355, 134.98358; 252.92078, 124.42062; 274.09152, 100.6524; 252.08675, 125.08897]

Frame-4

hg : [2523.743444745383, -3436.790363876738, -6320.163263697045;
      1152.68745032164, -1181.519781694952, -18248.99783312392;
      10.26100642365376, -14.53251070681075, 1]
obj_corners : [0, 0; 153, 0; 153, 94; 0, 94]
scene_corners : [-6320.1631, -18248.998; 241.77501, 100.64852; 277.01508, 229.64558; 241.293, 94.730072]

the "obj_corners is equal to the reference image dimensions(153*94)"

but the "scene_corners is either negative or random and mostly all points are almost at the same location".

Is the find homography hg value correct it is sometimes negative? Is the error with findHomography or perspectiveTransform.