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

相關問題