Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Just reposting from the comments above with nice code formatting. In short, there appears to be an issue when using the BOWImgDescriptorExtractor on the above ORB BoW approach. Here is some sample code:

int dictionarySize = 1024;
TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.00001);
int retries = 1;
int flags = KMEANS_PP_CENTERS;

// How the objects are set up
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("ORB");
Ptr<FeatureDetector> detector = FeatureDetector::create("Dense");
BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor bowDE(extractor, matcher)

// ...
// ... code here is equivalent to answer above for computing BoW but has been excluded for brevity ... 
// ...

// Read in the image that we want to match against the descriptor
Mat img = imread(entryPath.string(), 1);
cvtColor(img, img, CV_BGR2GRAY);

// Get the keypoints
vector<KeyPoint> keypoints;
detector->detect(img, keypoints);

// Try to get the descriptor
Mat bowDescriptor = Mat(0, 32, CV_32F);
bowDE.compute(img, keypoints, bowDescriptor); // <-- errors here

And the error is:

"OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in knnMatchImpl, file /Users/jamescharters/Downloads/opencv-2.4.6.1/modules/features2d/src/matchers.cpp, line 351"

I am doing this in C++ using OpenCV 2.4.6.1 on Mac OS 10.8.4.

Just reposting from the comments above with nice code formatting.

In short, there appears to be an issue when using the BOWImgDescriptorExtractor on the above ORB BoW approach. This might trip up other people, and seems closely related to the above question.

Here is some sample code:

int dictionarySize = 1024;
TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.00001);
int retries = 1;
int flags = KMEANS_PP_CENTERS;

// How the objects are set up
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("ORB");
Ptr<FeatureDetector> detector = FeatureDetector::create("Dense");
BOWKMeansTrainer bowTrainer(dictionarySize, tc, retries, flags);
BOWImgDescriptorExtractor bowDE(extractor, matcher)

// ...
// ... code here is equivalent to answer above for computing BoW but has been excluded for brevity ... 
// ...

// Read in the image that we want to match against the descriptor
Mat img = imread(entryPath.string(), 1);
cvtColor(img, img, CV_BGR2GRAY);

// Get the keypoints
vector<KeyPoint> keypoints;
detector->detect(img, keypoints);

// Try to get the descriptor
Mat bowDescriptor = Mat(0, 32, CV_32F);
bowDE.compute(img, keypoints, bowDescriptor); // <-- errors here

And the error is:

"OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in knnMatchImpl, file /Users/jamescharters/Downloads/opencv-2.4.6.1/modules/features2d/src/matchers.cpp, line 351"

I am doing this in C++ using OpenCV 2.4.6.1 on Mac OS 10.8.4.