[][src]Trait opencv::face::FacemarkTrain

pub trait FacemarkTrain: Facemark {
    fn as_raw_FacemarkTrain(&self) -> *mut c_void;

    fn add_training_sample(
        &mut self,
        image: &dyn ToInputArray,
        landmarks: &dyn ToInputArray
    ) -> Result<bool> { ... }
fn training(&mut self, parameters: &mut c_void) -> Result<()> { ... }
fn get_faces(
        &mut self,
        image: &dyn ToInputArray,
        faces: &mut dyn ToOutputArray
    ) -> Result<bool> { ... }
fn get_data(&mut self, items: &mut c_void) -> Result<bool> { ... } }

Abstract base class for trainable facemark models

To utilize this API in your program, please take a look at the @ref tutorial_table_of_content_facemark

Description

The AAM and LBF facemark models in OpenCV are derived from the abstract base class FacemarkTrain, which provides a unified access to those facemark algorithms in OpenCV.

Here is an example on how to declare facemark algorithm:

This example is not tested
// Using Facemark in your code:
Ptr<Facemark> facemark = FacemarkLBF::create();

The typical pipeline for facemark detection is listed as follows:

  • (Non-mandatory) Set a user defined face detection using FacemarkTrain::setFaceDetector. The facemark algorithms are designed to fit the facial points into a face. Therefore, the face information should be provided to the facemark algorithm. Some algorithms might provides a default face recognition function. However, the users might prefer to use their own face detector to obtains the best possible detection result.
  • (Non-mandatory) Training the model for a specific algorithm using FacemarkTrain::training. In this case, the model should be automatically saved by the algorithm. If the user already have a trained model, then this part can be omitted.
  • Load the trained model using Facemark::loadModel.
  • Perform the fitting via the Facemark::fit.

Required methods

Loading content...

Provided methods

fn add_training_sample(
    &mut self,
    image: &dyn ToInputArray,
    landmarks: &dyn ToInputArray
) -> Result<bool>

Add one training sample to the trainer.

Parameters

  • image: Input image.
  • landmarks: The ground-truth of facial landmarks points corresponds to the image.

Example of usage

This example is not tested
String imageFiles = "../data/images_train.txt";
String ptsFiles = "../data/points_train.txt";
std::vector<String> images_train;
std::vector<String> landmarks_train;

// load the list of dataset: image paths and landmark file paths
loadDatasetList(imageFiles,ptsFiles,images_train,landmarks_train);

Mat image;
std::vector<Point2f> facial_points;
for(size_t i=0;i<images_train.size();i++){
image = imread(images_train[i].c_str());
loadFacePoints(landmarks_train[i],facial_points);
facemark->addTrainingSample(image, facial_points);
}

The contents in the training files should follows the standard format. Here are examples for the contents in these files. example of content in the images_train.txt

This example is not tested
/home/user/ibug/image_003_1.jpg
/home/user/ibug/image_004_1.jpg
/home/user/ibug/image_005_1.jpg
/home/user/ibug/image_006.jpg

example of content in the points_train.txt

This example is not tested
/home/user/ibug/image_003_1.pts
/home/user/ibug/image_004_1.pts
/home/user/ibug/image_005_1.pts
/home/user/ibug/image_006.pts

fn training(&mut self, parameters: &mut c_void) -> Result<()>

Trains a Facemark algorithm using the given dataset. Before the training process, training samples should be added to the trainer using face::addTrainingSample function.

Parameters

  • parameters: Optional extra parameters (algorithm dependent).

Example of usage

This example is not tested
FacemarkLBF::Params params;
params.model_filename = "ibug68.model"; // filename to save the trained model
Ptr<Facemark> facemark = FacemarkLBF::create(params);

// add training samples (see Facemark::addTrainingSample)

facemark->training();

C++ default parameters

  • parameters: 0

fn get_faces(
    &mut self,
    image: &dyn ToInputArray,
    faces: &mut dyn ToOutputArray
) -> Result<bool>

Detect faces from a given image using default or user defined face detector. Some Algorithm might not provide a default face detector.

Parameters

  • image: Input image.
  • faces: Output of the function which represent region of interest of the detected faces. Each face is stored in cv::Rect container.

Example of usage

This example is not tested
std::vector<cv::Rect> faces;
facemark->getFaces(img, faces);
for(int j=0;j<faces.size();j++){
cv::rectangle(img, faces[j], cv::Scalar(255,0,255));
}

fn get_data(&mut self, items: &mut c_void) -> Result<bool>

Get data from an algorithm

Parameters

  • items: The obtained data, algorithm dependent.

Example of usage

This example is not tested
Ptr<FacemarkAAM> facemark = FacemarkAAM::create();
facemark->loadModel("AAM.yml");

FacemarkAAM::Data data;
facemark->getData(&data);
std::vector<Point2f> s0 = data.s0;

cout<<s0<<endl;

C++ default parameters

  • items: 0
Loading content...

Implementors

impl FacemarkTrain for FacemarkLBF[src]

impl FacemarkTrain for PtrOfFacemarkAAM[src]

Loading content...