我尝试使用 OpenCV 制作描述符字典。当我使用 BOWKmeansTrainer 的方法 .cluster() 时,我的应用程序抛出未处理的异常
OpenCV 错误:未知函数中的断言失败(data.dims <= 2 && type == CV_32F && K > 0),文件......\src\opencv\modules\core\src\matrix.cpp,行2485 未知异常
我不明白为什么会这样。我试图更改参数,但没有帮助。
你能给我一些想法如何解决这个问题吗?
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;
}