5#include "sfe_toolkit/sfe_core.h"
6#include "sfe_toolkit/sfe_face.h"
15#include <unordered_map>
34 std::cout <<
"Help: Usage of the program." << std::endl;
35 std::cout <<
"Options:" << std::endl;
36 std::cout <<
"-h: Display help." << std::endl;
37 std::cout <<
"-p: Probe image file." << std::endl;
38 std::cout <<
"-d: Path to detector solver." << std::endl;
39 std::cout <<
"-l: Path to landmarks solver." << std::endl;
40 std::cout <<
"-g: Path to demographic attributes solver." << std::endl;
41 std::cout <<
"-t: Face detection threshold. <0,1>" << std::endl;
42 std::cout <<
"-m: Minimal face size in pixels to detect." << std::endl;
43 std::cout <<
"-x: Max face size in pixels to detect." << std::endl;
46int main(
int argc,
char *argv[]) {
49 std::unordered_map<std::string, std::string> args;
51 for (
int i = 1; i < argc; ++i) {
52 std::string arg = argv[i];
58 if (i + 1 < argc && argv[i + 1][0] !=
'-') {
59 args[arg] = argv[++i];
61 std::cerr <<
"Option " << arg <<
" requires a value." << std::endl;
65 std::cerr <<
"Unknown option: " << arg << std::endl;
85 utils::printFormatted(
"PARAMETERS");
86 std::cout <<
"Probe image: " <<
image_probe << std::endl;
91 std::cout <<
"Min face size [px]: " <<
face_size_min << std::endl;
92 std::cout <<
"Max face size [px]: " <<
face_size_max << std::endl;
96 utils::printToolkitInfo();
108 utils::printFormatted(
"LOADING solvers");
113 utils::checkError(error);
118 utils::checkError(error);
123 utils::checkError(error);
130 utils::printFormatted(
"FACE DETECTION");
136 error =
sfeImageDecode(image_data.data(), image_data.size(), &image);
137 utils::checkError(error);
144 size_t detection_count = 1;
146 &detected_face, &detection_count);
147 utils::checkError(error);
149 if (detection_count == 0) {
150 std::cout <<
"No face detected in the probe image." << std::endl;
153 std::cout <<
"Found " << detection_count
154 <<
" face(s) in the probe image. Using the face with highest "
166 utils::checkError(error);
173 utils::printFormatted(
"FACE DEMOGRAPHIC ATTRIBUTES");
175 landmarks.data(), &attributes);
176 utils::checkError(error);
181 std::cout <<
"Demographic attributes:" << std::endl;
182 std::cout <<
" Age: " << std::fixed << std::setprecision(1) << attributes.age
183 <<
" years" << std::endl;
184 std::cout <<
" Gender score: " << std::setprecision(2) << attributes.gender
185 <<
" (" << (attributes.gender > 0.0f ?
"female" :
"male") <<
")"
189 utils::printFormatted(
"FINISHED");
std::string solver_face_demographic
std::string solver_face_detect
Solvers to use in example, the defaults are filled in by CMake.
float detection_threshold
const auto SOLVER_PARAMETERS
size_t face_size_min
Required size of the face to be detected.
std::string solver_face_landmarks
void sfeSolverFree(SFESolver solver)
Free memory associated with SFESolver.
void * SFESolver
Solver provides an abstract interface over inference models and engines.
void * SFEError
Error type used to hold optional error message.
void sfeImageFree(SFEImage image)
Free memory associated with SFEImage.
SFEError sfeSolverCreate(const char *solver_file, const SFESolverParameter *solver_parameters, size_t solver_parameters_count, SFESolver *out_solver)
Create new solver from solver file.
SFEError sfeImageDecode(const unsigned char *data, size_t data_len, SFEImage *out_image)
Decode SFEImage from raw image data of various formats. Eg. PNG, JPEG ..
SFEError sfeDetect(SFESolver solver, SFEImageView image, float threshold, SFEDetection *out_detections, size_t *in_out_detection_count)
Detect objects in the source image using unified detection API.
SFEError sfeFaceDemographicAttributes(SFESolver solver, SFEImageView image, SFEFaceLandmarks face_landmarks[SFE_FACE_LANDMARK_COUNT], SFEFaceDemographicAttributes *out_demographic_attributes)
Estimate demographic attributes (age, gender) from a face image.
#define SFE_FACE_LANDMARK_COUNT
SFEError sfeFaceLandmarks(SFESolver solver, SFEImageView image, const SFEDetection *detection, SFEFaceLandmarks out_face_landmarks[SFE_FACE_LANDMARK_COUNT])
Detect 23 landmarks of the face detected in the area of source image marked with detection.
Core detection - tagged union containing all detection types.
Demographic attributes of the detected face.
Raw owned raster image representation, HWC|BGR order.