2013-08-22 30 views
3

下面是我的代碼,這是運行良好,但長期處理後,告訴我在運行時錯誤獲取使用SVM與SURF錯誤

// Initialize constant values 
const int nb_cars = files.size(); 
const int not_cars = files_no.size(); 
const int num_img = nb_cars + not_cars; // Get the number of images 
// Initialize your training set. 
cv::Mat training_mat(num_img,dictionarySize,CV_32FC1); 
cv::Mat labels(0,1,CV_32FC1); 

std::vector<string> all_names; 

all_names.assign(files.begin(),files.end()); 
all_names.insert(all_names.end(), files_no.begin(), files_no.end()); 

// Load image and add them to the training set 
int count = 0; 
vector<string>::const_iterator i; 
string Dir; 
for (i = all_names.begin(); i != all_names.end(); ++i) 
{ 
    Dir=((count < files.size()) ? YourImagesDirectory : YourImagesDirectory_2); 

    Mat row_img = cv::imread(Dir +*i, 0); 

    detector.detect(row_img, keypoints); 

    RetainBestKeypoints(keypoints, 20); // retain top 10 key points 

    extractor->compute(row_img, keypoints, descriptors_1); 

    //uncluster.push_back(descriptors_1); 
    descriptors.reshape(1,1); 

    bow.add(descriptors_1); 

    ++count; 
} 

int count_2=0; 
vector<string>::const_iterator k; 
Mat vocabulary = bow.cluster(); 
dextract.setVocabulary(vocabulary); 


for (k = all_names.begin(); k != all_names.end(); ++k) 
{ 
    Dir=((count_2 < files.size()) ? YourImagesDirectory : YourImagesDirectory_2); 

    row_img = cv::imread(Dir +*k, 0); 

    detector.detect(row_img, keypoints); 

    RetainBestKeypoints(keypoints, 20); 

    dextract.compute(row_img, keypoints, descriptors_1); 

    descriptors_1.reshape(1,1); 

    training_mat.push_back(descriptors_1); 

    labels.at<float>(count_2, 0) = (count_2<nb_cars)?1:-1; 

    ++count_2; 
} 

錯誤:

OpenCv Error : Formats of input argument do not match() in unknown function , file ..\..\..\src\opencv\modules\core\src\matrix.cpp, line 652 

enter image description here

我在第二個循環中將descriptor_1重新整形爲SVM行,但錯誤未解決

+0

關於使用什麼: '墊labelsMat(num_img,CV_32FC1,標籤);'' 墊training_mat(num_img,CV_32FC1,trainingData);' – 2013-08-24 21:31:33

+0

@Flying你想說我的論點沒有組織? – Rocket

回答

0

至於我3天后發現我的錯誤是在貼標籤,當我標籤的圖像我得到了錯誤那裏,是的以上答案也是相關的,使用較少數量的圖像也導致錯誤,但在我的情況,這是不是這個原因,當我開始檢查由線誤差線,錯誤就從這裏開始:

labels.at<float>(count_2, 0) = (count_2<nb_cars)?1:-1; 

由於線:

Mat labels(0,1,CV_32FC1); 

相反的:

Mat labels(num_img,1,CV_32FC1); 

,我應該使用

my_img.convertTo(training_mat.row(count_2), CV_32FC1); 
0

我認爲你正在嘗試使用較少的功能進行羣集,然後是類的數量。

您可以從每個圖像中拍攝更多圖像或更多然後10個描述符。

+0

+1,這可能是錯誤的原因之一,但看看錯誤'開始第6步後'意味着最後/最後一個循環中的主要錯誤 – 2013-08-28 16:05:44

+0

@GilLevi當我一行一行地檢查它,我得到了錯誤這裏:'training_mat.push_back(descriptors_1);' – Rocket