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.
what errors do you get ? afaik, surf & sift descriptors are float mats, brief and freak are uchar
I get this error..
OpenCV Error: Assertion failed (queryDescriptors.type() == trainDescCollection[0].type()) in knnMatchImpl, file /home/ppillai/programs/opencv-2.4.5/modules/features2d/src/matchers.cpp, line 351 terminate called after throwing an instance of 'cv::Exception' what(): /home/ppillai/programs/opencv-2.4.5/modules/features2d/src/matchers.cpp:351: error: (-215) queryDescriptors.type() == trainDescCollection[0].type() in function knnMatchImpl
Try converting your descriptors fro; CV_8UC1 to CV_32FC1.
I tried the conversion yesterday, but I got a Segmentation fault.
this is the function that results in the segmentation fault:
bowExtractor->compute( colorImage, keypoints, imageDescriptors );