1
OpenCV Error: Bad argument (Empty training data was given. You'll need more than one sample to learn a model.) in train, file C:/slave/WinInstallerMegaPack/src/opencv/modules/contrib/src/facerec.cpp, line 316列車錯誤和預測我的opencv程序
當我嘗試運行下面的程序時出現上述錯誤。我的意圖是提供一些輸入圖像,並檢查opencv的train()
和predict()
函數。下面的代碼段中有什麼不對嗎?
int main(int argc, char* argv[]) {
const char * trainImage[6] = { "c:\\train\\00000000.jpg", "c:\\train\\00000001.jpg", "c:\\train\\00000002.jpg", "c:\\train\\00000003.jpg", "c:\\train\\00000004.jpg", "c:\\train\\00000005.jpg" };
int imglabel[6] = {1, 2, 3, 4, 5, 6};
vector<Mat> img = vector<Mat>();
vector<int> label = vector<int>();
for (int i = 0; i >= 5; i++) {
img.push_back(imread(trainImage[i], 0));
label.push_back(imglabel[i]);
}
Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
model->train(img, label);
model->save("c:\\train\\file.yaml");
// Testing...
model->load("c:\\train\\file.yaml");
Mat testsample = imread("c:\\test\\00000000.jpg", -1);
int PredictLabel = -1;
double confidence = 0.0;
model->predict(testsample, PredictLabel, confidence);
cout << PredictLabel;
return 0;
}
感謝您的答覆。我照你說的現在我得到錯誤OpenCV Error:Unspecified error(File無法打開寫入!)在加載,文件C:/slave/WinInstallerMegaPack/src/opencv/modules/contrib/src/facerec.cpp,304行 – 2vision2
也許你無法訪問該文件夾,嘗試更改路徑到'「file.yml」' – Cfr
我再次遇到同樣的錯誤! – 2vision2