# Revision history [back]

### knnMatch with k = 2 returns 0 nearest-neighbour

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5) I have tried with SIFT and it happens the same thing

### knnMatch with k = 2 returns 0 nearest-neighbour

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5) I have tried with SIFT and it happens the same thing

### knnMatch with k = 2 returns 0 nearest-neighbour

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5) 2.4.5)
I have tried with SIFT and it happens the same thing

Maybe it's because the reference to the vector<Mat> that i pass to the matcher.add(); gets lost ?

### knnMatch with k = 2 returns 0 nearest-neighbour

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

Maybe it's because the reference to the vector<Mat> that i pass to the matcher.add(); gets lost ?

### knnMatch with k = 2 returns 0 nearest-neighbour

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

Maybe it's because the reference I have tried to the vector<Mat> that i pass to the matcher.add(); gets lost ?check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything

### knnMatch with k = 2 returns 0 nearest-neighbour

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everythingeverything. To check this, if i do:

cout << matcher->getTrainDescriptors().at(0).size(); // (Get the size of the descriptors Mat associated to the first training image)


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

Note: the same code works fine if i use ORB :S

### knnMatch with k = 2 returns 0 nearest-neighbournearest-neighbour after a while

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

cout << matcher->getTrainDescriptors().at(0).size(); // (Get the size of the descriptors Mat associated to the first training image)


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

Note: the same code works fine if i use ORB :Sinstead of SURF or SIFT

### knnMatch with k = 2 returns 0 nearest-neighbour after a while

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

cout << matcher->getTrainDescriptors().at(0).size(); // (Get the size of the descriptors Mat associated to the first training image)


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

Note: the (The same code works fine if i use ORB instead of SURF or SIFTSIFT)

Also NOTE that If I change .knnMatch with a simple .match the code works normally!

### knnMatch with k = 2 returns 0 nearest-neighbour after a while

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

cout << matcher->getTrainDescriptors().at(0).size(); // (Get the size of the descriptors Mat associated to the first training image)
cout << matcher->getTrainDescriptors().at(0).size();


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

(The same code works fine if i use ORB instead of SURF or SIFT)

Also NOTE that If I change .knnMatch with a simple .match the code works normally!

### knnMatch with k = 2 returns 0 nearest-neighbour after a while

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

// (Get the size of the descriptors Mat associated to the first training image)
cout << matcher->getTrainDescriptors().at(0).size();


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

(The same code works fine if i use ORB instead of SURF or SIFT)

Also NOTE that If I change .knnMatch with a simple .match the code works matcher returns all DMatches normally!

### knnMatch with k = 2 returns 0 nearest-neighbour after a while

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added only a few of images, all works fine, but at some point when I try to:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have inserted more than 20-30 images. an image with only one keypoint/descriptor. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

// (Get the size of the descriptors Mat associated to the first training image)
cout << matcher->getTrainDescriptors().at(0).size();


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

(The same code works fine if i use ORB instead of SURF or SIFT)

Also NOTE that If I change .knnMatch with a simple .match the matcher returns all DMatches normally!normally! The code fails only with knnMatch

### knnMatch with k = 2 returns 0 nearest-neighbour after a while

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added an image with only a few of images, all works fine, but at some point when I try to:1 keypoint/descriptor and I use knnMatch:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have an image with only one keypoint/descriptor. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

// (Get the size of the descriptors Mat associated to the first training image)
cout << matcher->getTrainDescriptors().at(0).size();


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

Also NOTE that If I change .knnMatch with a simple .match the matcher returns all DMatches normally! The code fails only with knnMatch

### knnMatch with k = 2 returns 0 nearest-neighbour after a whilewith images with 1 keypoint

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added an image with only 1 keypoint/descriptor and I use knnMatch:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have an image with only one keypoint/descriptor. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

// (Get the size of the descriptors Mat associated to the first training image)
cout << matcher->getTrainDescriptors().at(0).size();


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

Also NOTE that If I change .knnMatch with a simple .match the matcher returns all DMatches normally! The code fails only with knnMatch

### knnMatch with k = 2 returns 0 nearest-neighbour with images with 1 keypoint

I am basically extracting many keypoints with SURF from similar images and adding them to the

BFMatcher(NORM_L2)


After I have calculate all descriptors from my keypoints and I have a

Mat descriptors;
vector<Mat> vectDesc;
vectDesc.push_back(descriptors);


Now when I have added add an image with only 1 keypoint/descriptor and I use knnMatch:

matcher->knnMatch(queryDesc,matches,2);


I get a vector with 0 Nearest-neighbour. If i do:

for(auto i = 0; i <matches.size(); i++) {
cout << "matches size: "<<matches[i].size()<<endl;


I get printed

"matches size: 0"
"matches size: 0"
"matches size: 0"
...


This happens only when I have an image with only one keypoint/descriptor. Before the knnMatch works fine.

What it could be? (Version 2.4.5)
I have tried with SIFT and it happens the same thing

I have tried to check if matcher.getTrainDescriptors(); contains my descriptors and effectively it contains everything. To check this, if i do:

// (Get the size of the descriptors Mat associated to the first training image)
cout << matcher->getTrainDescriptors().at(0).size();


I get: [128 x 32]. This means that descriptors are there but the knnMatches return an empty vector

Also NOTE that If I change .knnMatch with a simple .match the matcher returns all DMatches normally! The code fails only with knnMatch