I'm creating the visual histograms (following the Bag of Visual Words model) of a dataset of n
images using OpenCV.
This is the code:
std::vector<std::string> fileList;
std::unique_ptr<cv::BOWImgDescriptorExtractor> bowDE;
cv::Mat vocabulary;//will be filled through KMeans
...
bowDE->setVocabulary(vocabulary);
cv::Ptr<cv::Feature2D> featureDetectorDescriptor = cv::xfeatures2d::SIFT::create(0,3,0.04,10,1.6);;
for(size_t i=0;i<n;i++) {
cv::UMat img;
cv::Mat word;
imread(fileList[i], cv::IMREAD_GRAYSCALE).copyTo(img);
std::vector<cv::KeyPoint> keyPoints;
featureDetectorDescriptor->detect(img, keyPoints);
bowDE->compute(img, keyPoints, word);
histograms.push_back(word);
assert(histograms.rows==(i+1));//this is for testing
}
The problem is that after 4625
images have been inserted, the assert
condition is false. I tested keypoints.size()
and it results 0, no keypoints are detected!
I tried to remove the image which created the error, but another one creates the same error (so the error seems not to depend from the image).
Why this happens?
Update: actually I found out that the error was image dependent. It seems that with the default parameters cv::SIFT
detects 0 keypoints with this image from Caltech101: