本文整理汇总了C++中cv::Ptr::train方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::train方法的具体用法?C++ Ptr::train怎么用?C++ Ptr::train使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv::Ptr
的用法示例。
在下文中一共展示了Ptr::train方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: train
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);
}
示例2: getAssetPath
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
}
示例3: loadKNNDataAndTrainKNN
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;
}
示例4: setup
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);
}
示例5: trainModel
/*
* 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);
}
}