0

我尽量让描述符的字典中以OpenCV的。 当我使用BOWKmeansTrainer的方法.cluster(),我的应用程序将引发未处理的异常为什么我得到未处理的异常时,试图计算集群

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

我不明白为什么会发生。我试图改变参数,但它没有帮助。

你能不能给我一些想法如何,我可以解决这个问题?

INT主(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; 

}

+0

异常消息告诉你的问题是什么。慢慢仔细阅读。 – karlphillip

+0

我帮助他:'尺寸<= 2'和'类型== CV_32F'和'K> 0'。所以要么选择其他类型,要么获得更多维度。 –

+1

我有一个很难理解的例外。特别是,我不明白“<= 2”的含义。有没有人建议仔细阅读例外,谁也能解释这些尺寸是什么? –

回答

0

你是否检查了您送入BOWKMeansTrainer的关键点和描述符是有效的?我认为这可能是一个很好的开始。

我能描述送入使用SIFT一个BOWKMeansTrainer,但不知道如何使用这个哈里斯/ BRIEF。下面是SIFT方法的代码:

Mat allDescriptors; 
    SiftDescriptorExtractor detector; 
    for (int i = 1; i <= 10; i++) { 
     // get keypoints 
     vector<KeyPoint> keypoints; 
     // assuming you have a function intToString that converts your iterator to a string, 
     // this line creates a file path, e.g. /home/ubuntu/1.jpg to /home.ubuntu/10.jpg 
     string imagePath = "<put path to your image here>" + "/" + intToString(i) + ".jpg"; 
     Mat imageToUse = imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE); //Load as grayscale 
     detector.detect(imageToUse, keypoints); 
     // get descriptors 
     Mat descriptors; 
     detector.compute(imageToUse, keypoints,descriptors); 
     // load descriptors into your descriptor array 
     allDescriptors.push_back(descriptors); 
    } 

此代码使用SiftDescriptorExtractor两者的关键点检测和描述符提取。如果将关键点和描述符保存到文件中,您可以看到它们是尺寸为128 * n的Mats。尝试将您的描述符保存在一个文件中,并检查它们是否具有您期望的尺寸。

如果不是这样,那么它可能是你用于教练的parms。

好运。 BOWKMeans真的很难建立。

+0

碰巧我刚刚得到这个同样的错误,这是因为我的描述垫是空的。 – Darren

相关问题