vitis::ai::FaceLandmark

Base class for detecting five key points, and the score from a face image (cv::Mat).

Input a face image (cv::Mat).

Output score, five key points of the face.

Sample code:

Note: Usually the input image contains only one face. When it contains multiple faces, the functions returns the highest score.
cv:Mat image = cv::imread("sample_facelandmark.jpg");
auto landmark  = vitis::ai::FaceLandmark::create("face_landmark");
auto result = landmark->run(image);
float score = result.score;
auto points = result.points;
for(int i = 0; i< 5 ; ++i){
    auto x = points[i].frist  * image.cols;
    auto y = points[i].second * image.rows;
}

Display of the model results:

Figure 1: result image

Image sample_facelandmark_result.jpg

Quick Function Reference

The following table lists all the functions defined in the vitis::ai::FaceLandmark class:

Table 1. Quick Function Reference
TypeNameArguments
std::unique_ptr< FaceLandmark >create
  • const std::string & model_name
  • bool need_preprocess
std::unique_ptr< FaceLandmark >create
  • void
intgetInputWidth
  • void
intgetInputHeight
  • void
size_tget_input_batch
  • void
FaceLandmarkResultrun
  • const cv::Mat & input_image
std::vector< FaceLandmarkResult >run
  • const std::vector< cv::Mat > & input_images

create

Factory function to get an instance of derived classes of class FaceLandmark.

Prototype

std::unique_ptr< FaceLandmark > create(const std::string &model_name, bool need_preprocess=true);

Parameters

The following table lists the create function arguments.

Table 2. create Arguments
Type Name Description
const std::string & model_name Model name
bool need_preprocess Normalize with mean/scale or not, default value is true.

Returns

An instance of FaceLandmark class.

create

Prototype

std::unique_ptr< FaceLandmark > create(const std::string &model_name, xir::Attrs *attrs, bool need_preprocess=true);

getInputWidth

Function to get InputWidth of the landmark network (input image columns).

Prototype

int getInputWidth() const =0;

Returns

InputWidth of the face landmark network.

getInputHeight

Function to get InputHeight of the landmark network (input image rows).

Prototype

int getInputHeight() const =0;

Returns

InputHeight of the face landmark network.

get_input_batch

Function to get the number of images processed by the DPU at one time.

Note: Different DPU core the batch size may be different. This depends on the IP used.

Prototype

size_t get_input_batch() const =0;

Returns

Batch size.

run

Function to get running result of the face landmark network.

Set data of a face(e.g. data of cv::Mat) and get the five key points.

Prototype


            FaceLandmarkResult run(const cv::Mat &input_image)=0;

Parameters

The following table lists the run function arguments.

Table 3. run Arguments
Type Name Description
const cv::Mat & input_image Input data of input image (cv::Mat) of detected by the facedetect network and resized as inputwidth and inputheight.

Returns

The struct of FaceLandmarkResult

run

Function to get running results of the face landmark neuron network in batch mode.

Prototype

std::vector< FaceLandmarkResult > run(const std::vector< cv::Mat > &input_images)=0;

Parameters

The following table lists the run function arguments.

Table 4. run Arguments
Type Name Description
const std::vector< cv::Mat > & input_images Input data of input images (std:vector<cv::Mat>). The size of input images equals batch size obtained by get_input_batch. The input images need to be resized to InputWidth and InputHeight required by the network.

Returns

The vector of FaceLandmarkResult.