I am trying to do classification of images with combining SIFT features, Bag of Visual Words and SVM.
Now I am on training part. I need to get BoW histograms for each training image to be able to train SVM. For this I am using BOWImgDescriptorExtractor from OpenCV. I am using OpenCV version 3.1.0.
The problem is that it computes histogram for some images, but for some of images it gives me this error:
OpenCV Error: Assertion failed (queryIdx == (int)i) in compute,
file /Users/opencv-3.1.0/modules/features2d/src/bagofwords.cpp, line 200
libc++abi.dylib: terminating with uncaught exception of type
cv::Exception: /Users/opencv-3.1.0/modules/feature/src/bagofwords.cpp:200: error: (-215) queryIdx == (int)i in function compute
Training images are all of the same size, all have same number of channels. For creating dictionary I use another image set than for training SVM.
Here's part of code:
Ptr<FeatureDetector> detector(cv::xfeatures2d::SIFT::create());
Ptr<DescriptorMatcher> matcher(new BFMatcher(NORM_L2, true));
BOWImgDescriptorExtractor bow_descr(det, matcher);
bow_descr.setVocabulary(dict);
Mat features_svm;
for (int i = 0; i < num_svm_data; ++i) {
Mat hist;
std::vector<KeyPoint> keypoints;
detector->detect(data_svm[i], keypoints);
bow_descr.compute(data_svm[i], keypoints, hist);
features_svm.push_back(hist);
}
data_svm is a vector<Mat> type. It is my training set images which I will use in SVM.
What the problem can be?
data[i],keypointsandhistbefore you call the compute method. Anything odd about them? - Dan Mašekkeypointson image withdrawKeypoints()function,histfor images for which program gives me result looks good,keypointsfor all images looks good, anddata[i]which is one image also looks good. - York'shistbefore calling compute method is empty. - York'ssources\modules\features2d\src\bagofwords.cppstarting with line 143. First it computes descriptors using SIFT, then finds matches with BFMatcher. Processing of those matches then causes an error.Maybe there keypoints are not good enough for this picture? Try calculating those yourself and inspecting the results (or break inside the opencv code). Maybe try tweaking the parameters of the detector or matcher, or try different algorithms? - Dan Mašekmatches[i].queryIdx,matches[i].trainIdx. Can you explain them to me? - York's