Ask Your Question

ThevenonP's profile - activity

2014-10-31 15:36:26 -0600 received badge  Teacher (source)
2013-11-14 06:23:15 -0600 commented answer knnMatch gives wrong number of neighbours

I also had issues with vector<vector<DMatch>> objects that disappeaed by changing my IDE parameters. So I would definitely believe that it was the use of the VC10 files.

2013-11-12 17:49:45 -0600 received badge  Editor (source)
2013-11-12 17:49:08 -0600 answered a question knnMatch gives wrong number of neighbours

I found a solution when I changed some IDE parameters and when updating to OpenCV 2.4.7.

So the solution was:

  • either the change to OpenCV 2.4.7 was beneficial,
  • Or it was to configure Visual Studio Express 2012 to use the VC11 compiler instead of the VC10.
2013-11-11 17:40:27 -0600 received badge  Supporter (source)
2013-11-11 17:19:10 -0600 received badge  Critic (source)
2013-10-29 09:08:51 -0600 answered a question matcher tutorial

I would link to another post with good answer on how to refine matches : http://stackoverflow.com/questions/8118825/how-to-reduce-matches-in-opencv-pattern-recognition

There are several ways to improve the matching performances, basically by making sure that the matches you have found are reliable. I think this is the way to go, rather than trying to improve the preprocessing on your images.

2013-10-28 08:52:44 -0600 received badge  Necromancer (source)
2013-10-28 02:15:19 -0600 answered a question Object recognition knnmatch

knnMatch outputs the list of k nearest neighbours as a vector<vector<dmatch>>. It means that for each feature in the query image, it will output k (or less) DMatch, hence the need for a 2D structure.

If you only need 1 neighbour for each query image feature, you can use the .match() method, with the output as a vector<dmatch>.

2013-10-27 20:28:41 -0600 asked a question knnMatch gives wrong number of neighbours

Hello everyone,

I have an issue implementing one recipe from the book "OpenCV 2 Computer vision Application Programming" that I see around, which uses knnMatch.

Here is the code I use:

#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\nonfree\features2d.hpp>
#include <opencv2\calib3d\calib3d.hpp>
#include <opencv2\highgui\highgui.hpp>

using namespace cv;
using namespace std;

int main() {
    Mat image1 = imread(filename_object, CV_LOAD_IMAGE_GRAYSCALE);
    Mat image2 = imread(filename_scene, CV_LOAD_IMAGE_GRAYSCALE);

    // 1a. Detection of the features
    SIFT detector;
    vector<KeyPoint> keypoints1, keypoints2;
    detector.detect(image1,keypoints1);
    detector.detect(image2,keypoints2);
    cout << keypoints1.size() << " features found in image 1.\n";
    cout << keypoints2.size() << " features found in image 2.\n";

    // 1b. Extraction of features' descriptors
    Mat descriptors1, descriptors2;
    SiftDescriptorExtractor extractor;
    extractor.compute(image1,keypoints1,descriptors1);
    extractor.compute(image2,keypoints2,descriptors2);
    cout << descriptors1.size() << " descriptors found in image 1.\n";
    cout << descriptors2.size() << " descriptors found in image 2.\n";

    // 2. Match the two image descriptors
    // Construction of the matcher
    BFMatcher matcher;
    vector<vector<DMatch>> matches_multiple_1, matches_multiple_2;
    matcher.knnMatch(descriptors1,descriptors2,matches_multiple_1,2);
    matcher.knnMatch(descriptors2,descriptors1,matches_multiple_2,2);

    cout << matches_multiple_1.size() << " simple 1->2 matches found.\n";
    for (int i=0; i<9; i++)
        cout << "1->2 - query descriptor #" << i+1 << " - number of neighbours: " << matches_multiple_1[i].size() << "\n";
    cout << matches_multiple_2.size() << " simple 2->1 matches found.\n";
    for (int i=0; i<9; i++)
        cout << "2->1 - query descriptor #" << i+1 << " - number of neighbours: " << matches_multiple_2[i].size() << "\n";

    waitKey();
    exit(0);
}

When I run this code, I obtain the following text in my console:

142 features found in image 1.
2269 features found in image 2.
[128 x 142] descriptors found in image 1.
[128 x 2269] descriptors found in image 2.
189 simple 1->2 matches found.
1->2 - query descriptor #1 - number of neighbours: 2
1->2 - query descriptor #2 - number of neighbours: 312192029373266162
1->2 - query descriptor #3 - number of neighbours: 18134552044336285451
1->2 - query descriptor #4 - number of neighbours: 0
1->2 - query descriptor #5 - number of neighbours: 2
1->2 - query descriptor #6 - number of neighbours: 312192029373199793
1->2 - query descriptor #7 - number of neighbours: 18134552044336351820
1->2 - query descriptor #8 - number of neighbours: 0
1->2 - query descriptor #9 - number of neighbours: 2
3025 simple 2->1 matches found.
2->1 - query descriptor #1 - number of neighbours: 2
2->1 - query descriptor #2 - number of neighbours: 312192029372759970
2->1 - query descriptor #3 - number of neighbours: 18134552044336791643
2->1 - query descriptor #4 - number of neighbours: 0
2->1 - query descriptor #5 - number of neighbours: 2
2->1 - query descriptor #6 - number of neighbours: 312192029372759985
2->1 - query descriptor #7 - number of neighbours: 18134552044336791628
2->1 - query descriptor #8 - number of neighbours: 0
2->1 - query descriptor #9 - number of neighbours: 2

What I do not understand, is why some elements of the Vector matches_multiple_1 and _2 have not the right size, notably, the zero value and the very large values.

I tried to go back from scratch several ... (more)