void train( std::vector<cv::Mat> &images, std::vector<int> &labels ) { // //turn all images to grey and same size // for( cv::Mat image : images ) // { // cv::cvtColor(image, image, CV_BGR2GRAY); // cv::resize(image, image, cv::Size(500, 500)); // // cv::imshow("face", image); // cv::waitKey(); // } eigenfaceRecognizor->train(images, labels); fisherfaceRecognizor->train(images, labels); LBPHRecognizor->train(images, labels); }
void TellThatToMyCamera_v1_0App::setup() { mExpressionsCascade.load(getAssetPath("haarcascade_frontalface_alt.xml").string()); mPath= getAssetPath("ppdtest.csv").string(); mCapture = Capture( 640, 480 ); // Camera settings mCapture.start(); read_csv(mPath, mDBimgFaces, mDBLabels); // Read DB of faces for FaceRec algorithm mFisherFaceRec->train(mDBimgFaces, mDBLabels); // Train the Fisher Face Recognizer algorithm }
bool loadKNNDataAndTrainKNN(void) { // read in training classifications /////////////////////////////////////////////////// cv::Mat matClassificationInts; // we will read the classification numbers into this variable as though it is a vector cv::FileStorage fsClassifications("classifications.xml", cv::FileStorage::READ); // open the classifications file if (fsClassifications.isOpened() == false) { // if the file was not opened successfully std::cout << "error, unable to open training classifications file, exiting program\n\n"; // show error message return(false); // and exit program } fsClassifications["classifications"] >> matClassificationInts; // read classifications section into Mat classifications variable fsClassifications.release(); // close the classifications file // read in training images //////////////////////////////////////////////////////////// cv::Mat matTrainingImagesAsFlattenedFloats; // we will read multiple images into this single image variable as though it is a vector cv::FileStorage fsTrainingImages("images.xml", cv::FileStorage::READ); // open the training images file if (fsTrainingImages.isOpened() == false) { // if the file was not opened successfully std::cout << "error, unable to open training images file, exiting program\n\n"; // show error message return(false); // and exit program } fsTrainingImages["images"] >> matTrainingImagesAsFlattenedFloats; // read images section into Mat training images variable fsTrainingImages.release(); // close the traning images file // train ////////////////////////////////////////////////////////////////////////////// // finally we get to the call to train, note that both parameters have to be of type Mat (a single Mat) // even though in reality they are multiple images / numbers kNearest->setDefaultK(1); kNearest->train(matTrainingImagesAsFlattenedFloats, cv::ml::ROW_SAMPLE, matClassificationInts); return true; }
void ICPApp::setup() { mExpressionsCascade.load(getAssetPath("haarcascade_frontalface_alt.xml").string()); mPath= getAssetPath("ppdtest.csv").string(); mCapture = Capture( 640, 480 ); // Camera settings mCapture.start(); read_csv(mPath, mDBimgFaces, mDBLabels); // Read DB of faces for FaceRec algorithm mFisherFaceRec->train(mDBimgFaces, mDBLabels); // Train the Fisher Face Recognizer algorithm // FOR TESTING PURPOSES // mSurf=(loadImage("/Users/PpD/Desktop/EcA - Pp DanY/MSc ICP/Semester 2/ICP 3/Faces DB Original/hugh_laurie_extra1.jpg")); // mTexture = gl::Texture(mCinderDBimgFaces); // mTexture = gl::Texture( fromOcv( input ) ); // cv::Mat output; // mTexture = gl::Texture( fromOcv( loadImage("/Users/PpD/Desktop/emotionsrec2/data/emotions/0neutral/amy_adams_neutral.jpg") ) ); // mDBLabelsTEST.push_back(0); // mDBLabelsTEST.push_back(1); // mFisherFaceRec->train(mDBimgFaces, mDBLabelsTEST); // mFisherFaceRec->train(mDBimgFaces, mDBLabels); }
/* * Train any given model if it is not already trained */ void ModelTrainer::trainModel(cv::Ptr<cv::ml::StatModel> model) { if (model && !model->isTrained()) { cv::Ptr<cv::ml::TrainData> trainData = loadTrainingData(); model->train(trainData); } }