I try to make a dictionary of descriptors by using OpenCV. When I use method .cluster() of BOWKmeansTrainer, my application throws unhandled exception
OpenCV Error: Assertion failed (data.dims <= 2 && type == CV_32F && K > 0) in un known function, file ......\src\opencv\modules\core\src\matrix.cpp, line 2485 Unknown exception
I can't understand why it happens. I tried to change parameters, but it didn't help.
Could You give me some ideas how I can solve this problem?
int main(int argc, char* argv[]) {
const int countClusters = 2;
vector<string> fileList;
GetFilesInFolder(folder_one, fileList);
vector<bool> trainMask(fileList.size());
InitRandomBoolVector(trainMask, 0.1);
Ptr<FeatureDetector> keypointsDetector = FeatureDetector::create("HARRIS");
Ptr<DescriptorExtractor> descriptorsExtractor = DescriptorExtractor::create("BRIEF");
Mat descriptors;
Mat voc;
TermCriteria tc(TermCriteria::COUNT + TermCriteria::EPS, 10, 0.001);
BOWKMeansTrainer bowTrainer(vocSize,tc);
for(int i = 0;i < filesList.size();i++)
{
if(is_voc.at(i))
{
vector<KeyPoint> keypoints;
Mat image = imread(filesList.at(i));
keypointsDetector->detect(image,keypoints);
descriptorsExtractor->compute(image,keypoints,descriptors);
bowTrainer.add(descriptors);
}
}
try
{
voc = bowTrainer.cluster();
}
catch(std::exception ex)
{
printf(ex.what());
}
return 0;
}
dimensions <= 2
ANDtype == CV_32F
ANDK > 0
. So either choose another type or get more dimensions. – Thomas Jungblut