#include "sfe_toolkit/sfe_core.h"
#include "sfe_toolkit/sfe_face.h"
#include "annotate.hpp"
#include "solvers.h"
#include "utils.hpp"
#include <iomanip>
#include <iostream>
#include <sstream>
#include <unordered_map>
#include <vector>
std::string
image_probe =
"assets/face/images/obiwan0.png";
std::cout << "Help: Usage of the program." << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-h: Display help." << std::endl;
std::cout << "-p: Probe image file." << std::endl;
std::cout << "-d: Path to detector solver." << std::endl;
std::cout << "-l: Path to landmarks solver." << std::endl;
std::cout << "-g: Path to demographic attributes solver." << std::endl;
std::cout << "-t: Face detection threshold. <0,1>" << std::endl;
std::cout << "-m: Minimal face size in pixels to detect." << std::endl;
std::cout << "-x: Max face size in pixels to detect." << std::endl;
}
int main(
int argc,
char *argv[]) {
{
std::unordered_map<std::string, std::string> args;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg[0] == '-') {
if (arg == "-h") {
return 0;
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
args[arg] = argv[++i];
} else {
std::cerr << "Option " << arg << " requires a value." << std::endl;
return 1;
}
} else {
std::cerr << "Unknown option: " << arg << std::endl;
return 1;
}
}
if (args.count("-p"))
if (args.count("-d"))
if (args.count("-l"))
if (args.count("-g"))
if (args.count("-t"))
if (args.count("-m"))
if (args.count("-x"))
utils::printFormatted("PARAMETERS");
std::cout <<
"Probe image: " <<
image_probe << std::endl;
<< std::endl;
std::cout <<
"Min face size [px]: " <<
face_size_min << std::endl;
std::cout <<
"Max face size [px]: " <<
face_size_max << std::endl;
}
utils::printToolkitInfo();
{
utils::printFormatted("LOADING solvers");
utils::checkError(error);
utils::checkError(error);
utils::checkError(error);
}
{
utils::printFormatted("FACE DETECTION");
utils::checkError(error);
}
{
size_t detection_count = 1;
&detected_face, &detection_count);
utils::checkError(error);
if (detection_count == 0) {
std::cout << "No face detected in the probe image." << std::endl;
return 0;
} else {
std::cout << "Found " << detection_count
<< " face(s) in the probe image. Using the face with highest "
"confidence."
<< std::endl;
}
}
{
landmarks.data());
utils::checkError(error);
}
{
utils::printFormatted("FACE DEMOGRAPHIC ATTRIBUTES");
landmarks.data(), &attributes);
utils::checkError(error);
}
{
std::cout << "Demographic attributes:" << std::endl;
std::cout << " Age: " << std::fixed << std::setprecision(1) << attributes.age
<< " years" << std::endl;
std::cout << " Gender score: " << std::setprecision(2) << attributes.gender
<< " (" << (attributes.gender > 0.0f ? "female" : "male") << ")"
<< std::endl;
}
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.