5#include "sfe_toolkit/sfe_core.h"
6#include "sfe_toolkit/sfe_palm.h"
13#include "annotate.hpp"
16#include <unordered_map>
44 error =
sfeImageDecode(image_data.data(), image_data.size(), &image);
45 utils::checkError(error);
54 size_t detected_count = 1;
56 &detected_palm, &detected_count);
57 utils::checkError(error);
59 if (detected_count > 0 && detected_palm.
confidence < 0.5) {
60 throw std::runtime_error(
"No palm detected in the probe image.");
63 std::cout <<
"Found palm in the image. Extracting template..." << std::endl;
72 error =
sfePalmLandmarks(landmarks_solver, image, &detected_palm, &landmarks);
73 utils::checkError(error);
84 utils::checkError(error);
91 std::cout <<
"Help: Usage of the program." << std::endl;
92 std::cout <<
"Options:" << std::endl;
93 std::cout <<
"-h: Display help." << std::endl;
94 std::cout <<
"-p: Probe image file." << std::endl;
95 std::cout <<
"-g: Matching image file. Our \"palm database\"." << std::endl;
96 std::cout <<
"-d: Path to detector solver." << std::endl;
97 std::cout <<
"-l: Path to landmarks solver." << std::endl;
98 std::cout <<
"-e: Path to template extraction solver." << std::endl;
99 std::cout <<
"-t: Detection threshold. <0,1>" << std::endl;
100 std::cout <<
"-i: Identification threshold. <0,1>" << std::endl;
104int main(
int argc,
char *argv[]) {
108 std::unordered_map<std::string, std::string> args;
111 for (
int i = 1; i < argc; ++i) {
112 std::string arg = argv[i];
119 if (i + 1 < argc && argv[i + 1][0] !=
'-') {
120 args[arg] = argv[++i];
122 std::cerr <<
"Option " << arg <<
" requires a value." << std::endl;
126 std::cerr <<
"Unknown option: " << arg << std::endl;
132 if (args.count(
"-p"))
134 if (args.count(
"-g"))
136 if (args.count(
"-d"))
138 if (args.count(
"-l"))
140 if (args.count(
"-e"))
142 if (args.count(
"-i"))
145 utils::printFormatted(
"EXAMPLE PARAMETERS");
147 std::cout <<
"Probe image: " <<
image_probe << std::endl;
148 std::cout <<
"Matching image: " <<
image_match << std::endl;
160 utils::printToolkitInfo();
170 utils::printFormatted(
"LOADING SOLVERS");
175 utils::checkError(error);
180 utils::checkError(error);
185 utils::checkError(error);
190 utils::printFormatted(
"PROBE TEMPLATE EXTRACTION");
196 utils::printFormatted(
"PROBE TEMPLATE ATTRIBUTES");
201 utils::checkError(error);
203 std::cout <<
"Version of the probe template: " << version.
major <<
'.'
204 << version.
minor <<
'.' << version.
patch << std::endl;
208 size_t gallery_size = 10;
209 std::vector<SFEPalmTemplate> palm_template_gallery(gallery_size);
211 utils::printFormatted(
"PALM GALLERY EXTRACTION");
213 auto matching_palm_template =
216 auto non_matching_palm_template =
220 for (
size_t i = 0; i < gallery_size; i++) {
221 palm_template_gallery[i] = non_matching_palm_template;
225 palm_template_gallery[5] = matching_palm_template;
229 size_t candidate_count = 1;
230 std::vector<SFETemplateIdentificationCandidate> identification_results(
233 utils::printFormatted(
"1:N IDENTIFICATION");
236 &probe_palm_template, palm_template_gallery.
data(),
238 identification_results.data(), &candidate_count, 4);
239 utils::checkError(error);
241 if (candidate_count == 0) {
242 std::cout <<
"No candidates found above identification threshold "
247 std::cout <<
"Found " << identification_results.size()
248 <<
" candidates above identification threshold "
250 for (
auto &result : identification_results)
251 std::cout <<
"Template index: #" << result.index
252 <<
", score: " << result.score << std::endl;
258 utils::printFormatted(
"1:1 MATCHING");
260 if (identification_results.size() == 0) {
261 std::cout <<
"No candidates found above identification threshold "
267 auto match_palm_template =
268 palm_template_gallery[identification_results[0].index];
270 float match_confidence;
273 utils::checkError(error);
276 <<
"Matching score of probe template with the best template, score: "
277 << match_confidence << std::endl;
281 utils::printFormatted(
"FINISHED");
float identification_threshold
float detection_threshold
const auto SOLVER_PARAMETERS
SFEIrisTemplate extract_template(std::string image_path, SFESolver &detector_solver, SFESolver &template_solver)
std::string image_non_match
std::string solver_palm_landmarks
std::string solver_palm_detect
Solvers to use in example, the defaults are filled in by CMake.
std::string solver_palm_extraction
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 sfePalmLandmarks(SFESolver solver, SFEImageView image, const SFEDetection *detection, SFEPalmLandmarks *out_landmarks)
Calculate palm landmarks from given source image and palm detection.
SFEError sfePalmTemplateMatch(const SFEPalmTemplate *template1, const SFEPalmTemplate *template2, float *out_matching_score)
Match two palm templates.
SFEError sfePalmTemplateExtract(SFESolver solver, SFEImageView image, const SFEPalmLandmarks *landmarks, SFEPalmTemplate *out_palm_template)
Extract template from source image and given palm attributes.
SFEError sfePalmTemplateIdentify(const SFEPalmTemplate *probe_palm_template, const SFEPalmTemplate *templates_gallery, size_t gallery_size, float matching_score_threshold, SFETemplateIdentificationCandidate *out_candidates, size_t *in_out_candidates_count, size_t thread_count)
Get an ordered array of SFETemplateIdentificationCandidate from probe's template best matches with te...
SFEError sfePalmTemplateVersion(const SFEPalmTemplate *palm_template, SFEPalmTemplateVersion *out_palm_template_version)
Get palm template version.
Core detection - tagged union containing all detection types.
float confidence
Detection confidence - range <0,1> (common for all detection types)
Raw owned raster image representation, HWC|BGR order.
Palm landmarks (keypoints, hand position, orientation, confidence)
uint8_t data[SFE_PALM_TEMPLATE_SIZE]
Palm template version struct.
uint8_t patch
Patch template version.
uint8_t minor
Minor template version.
uint8_t major
Major template version.