Main fuction is used to parse command line arguments.
53 {
54
55 {
56
57 std::unordered_map<std::string, std::string> args;
58
59
60 for (int i = 1; i < argc; ++i) {
61 std::string arg = argv[i];
62 if (arg[0] == '-') {
63 if (arg == "-h") {
65 return 0;
66 }
67
68 if (i + 1 < argc && argv[i + 1][0] != '-') {
69 args[arg] = argv[++i];
70 } else {
71 std::cerr << "Option " << arg << " requires a value." << std::endl;
72 return 1;
73 }
74 } else {
75 std::cerr << "Unknown option: " << arg << std::endl;
76 return 1;
77 }
78 }
79
80
81 if (args.count("-p"))
83 if (args.count("-d"))
85 if (args.count("-i"))
86 solver_palm_liveness = args["-i"];
87 if (args.count("-t"))
89
90 utils::printFormatted("PARAMETERS");
91
92 std::cout <<
"Probe image: " <<
image_probe << std::endl;
93
94
96 std::cout << "Palm liveness solver: " << solver_palm_liveness << std::endl;
97
98
100 }
101
102 utils::printToolkitInfo();
103
105
110 {
111 utils::printFormatted("LOADING solvers");
112
116 utils::checkError(error);
117
118
122 utils::checkError(error);
123 }
124
127 {
128
129 utils::printFormatted("PALM DETECTION");
131
133
134
135 error =
sfeImageDecode(image_data.data(), image_data.size(), &image);
136 utils::checkError(error);
138 }
141 {
142 size_t detection_count = 1;
143
145 &detected_palm, &detection_count);
146 utils::checkError(error);
147
148 if (detection_count == 0) {
149 std::cout << "No palm detected in the probe image." << std::endl;
150 return 0;
151 } else {
152 std::cout << "Found " << detection_count
153 << " palm(s) in the probe image. Using the palm with highest "
154 "confidence."
155 << std::endl;
156 }
157 }
159
161
163 float liveness_score = 0.0f;
164 {
165 utils::printFormatted("LIVENESS CHECK");
167 &liveness_score);
168 utils::checkError(error);
169 }
171 {
172 std::cout << "Liveness score is " << liveness_score;
173
174 static const float LIVENESS_THRESHOLD = 0.8189f;
175 if (liveness_score < LIVENESS_THRESHOLD) {
176 std::cout << " which is below " << LIVENESS_THRESHOLD
177 << " threshold. Palm is spoof." << std::endl;
178 } else {
179 std::cout << " which is above " << LIVENESS_THRESHOLD
180 << " threshold. Palm is genuine." << std::endl;
181 }
182 }
183
184 {
185
186 std::stringstream label;
187 label << "Palm" << std::fixed << std::setprecision(2)
188 <<
" d:" << detected_palm.
confidence <<
" l:" << liveness_score;
189
190 annotate::labelBox(image, label.str(), detected_palm.
bounding_box,
191 annotate::WHITE, annotate::GREEN);
192
193
194 size_t size = image.width * image.height * 3;
195 auto png_file = std::vector<unsigned char>(size);
197 utils::checkError(error);
198 png_file.resize(size);
199 utils::saveFile("palm_liveness.png", png_file);
200
201 std::cout << std::endl;
202 std::cout << "Annotated image saved to palm_liveness.png" << std::endl;
203 }
204 utils::printFormatted("FINISHED");
205}
float detection_threshold
const auto SOLVER_PARAMETERS
std::string solver_palm_detect
Solvers to use in example, the defaults are filled in by CMake.
void printPalmDetectionInfo(SFEDetection &detected_palm)
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.
@ SFE_IMAGE_FORMAT_PNG
Portable Network Graphics format.
SFEError sfeImageEncode(SFEImageView image, SFEImageFormat image_format, unsigned char *out_data, size_t *in_out_data_len)
Encode SFEImage into a buffer with specified image_format.
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 sfePalmLivenessPassive(SFESolver solver, SFEImageView image, const SFEDetection *detection, float *out_liveness_score)
Passive liveness score calculation.
Core detection - tagged union containing all detection types.
SFEBoundingBox bounding_box
Bounding box (common for all detection types)
float confidence
Detection confidence - range <0,1> (common for all detection types)
Raw owned raster image representation, HWC|BGR order.