void Classifier::SaveClassifierToFile(string fileName) { if (em_model.isTrained() == false) return; FileStorage fs = FileStorage(fileName, FileStorage::WRITE); em_model.write(fs); fs.release(); }
//Learn classifier bool Classifier::Train(Mat sample) { cout << "Training classfication model..."; clock_t startTime_train = clock(); em_model.train(sample); clock_t endTime_train = clock(); double timeSec_train = (endTime_train - startTime_train) / static_cast<double>(CLOCKS_PER_SEC); cout << " train time = " << timeSec_train << "secs\n"; SaveClassifierToFile("em" + to_string(i) + ".xml"); i++; return em_model.isTrained(); }