5#include "sfe_toolkit/sfe_core.h"
6#include "sfe_toolkit/sfe_palm.h"
13#include "annotate.hpp"
16#include <unordered_map>
23#ifdef SOLVER_PALM_ATTRIBUTES
34 std::cout <<
"SFEDetection{ " << std::endl;
35 std::cout <<
" confidence: " << detected_palm.
confidence << std::endl;
36 std::cout <<
" hand_position: " << attributes.
hand_position << std::endl;
37 std::cout <<
" hand_orientation: " << attributes.
hand_orientation << std::endl;
38 std::cout <<
" SFEBoundingBox{ " << std::endl;
39 std::cout <<
" x: " << detected_palm.
bounding_box.
x << std::endl;
40 std::cout <<
" y: " << detected_palm.
bounding_box.
y << std::endl;
43 std::cout <<
" }" << std::endl;
44 std::cout <<
" Keypoints{ " << std::endl;
45 for (
auto &keypoint : attributes.
keypoints) {
46 std::cout <<
" SFEPalmKeypoint{ " << std::endl;
47 std::cout <<
" x: " << keypoint.x << std::endl;
48 std::cout <<
" y: " << keypoint.y << std::endl;
49 std::cout <<
" }" << std::endl;
51 std::cout <<
" }" << std::endl;
52 std::cout <<
" }" << std::endl;
53 std::cout << std::endl;
57 std::cout <<
"Help: Usage of the program." << std::endl;
58 std::cout <<
"Options:" << std::endl;
59 std::cout <<
"-h: Display help." << std::endl;
60 std::cout <<
"-p: Probe image file." << std::endl;
61 std::cout <<
"-d: Path to detector solver." << std::endl;
62 std::cout <<
"-i: Path to attributes solver." << std::endl;
63 std::cout <<
"-t: Palm detection threshold. <0,1>" << std::endl;
67int main(
int argc,
char *argv[]) {
71 std::unordered_map<std::string, std::string> args;
74 for (
int i = 1; i < argc; ++i) {
75 std::string arg = argv[i];
82 if (i + 1 < argc && argv[i + 1][0] !=
'-') {
83 args[arg] = argv[++i];
85 std::cerr <<
"Option " << arg <<
" requires a value." << std::endl;
89 std::cerr <<
"Unknown option: " << arg << std::endl;
101 if (args.count(
"-t"))
104 utils::printFormatted(
"PARAMETERS");
106 std::cout <<
"Probe image: " <<
image_probe << std::endl;
110 std::cout <<
"Palm attributes solver: "
118 utils::printToolkitInfo();
125 utils::printFormatted(
"LOADING solvers");
130 utils::checkError(error);
137 utils::printFormatted(
"PALM DETECTION");
143 error =
sfeImageDecode(image_data.data(), image_data.size(), &image);
144 utils::checkError(error);
150 size_t detection_count = 1;
153 &detected_palm, &detection_count);
154 utils::checkError(error);
156 if (detection_count == 0) {
157 std::cout <<
"No palm detected in the probe image." << std::endl;
160 std::cout <<
"Found " << detection_count
161 <<
" palm(s) in the probe image. Using the palm with highest "
171 utils::printFormatted(
"LANDMARKS");
173 error =
sfePalmLandmarks(detector_solver, image, &detected_palm, &landmarks);
174 utils::checkError(error);
185 utils::checkError(error);
188 utils::printFormatted(
"ATTRIBUTES");
192 utils::checkError(error);
196 std::cout <<
"Hand orientation " << attributes.
hand_orientation << std::endl;
197 std::cout <<
"Hand position " << attributes.
hand_position << std::endl;
198 std::cout <<
"Quality " << attributes.
quality << std::endl;
201 std::cout <<
"Palm attributes solver not specified, skipping attributes analysis." << std::endl;
204 utils::printFormatted(
"FINISHED");
float detection_threshold
const auto SOLVER_PARAMETERS
std::optional< std::string > solver_palm_attributes
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.
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 sfePalmAttributes(SFESolver solver, SFEImageView image, const SFEPalmLandmarks *landmarks, SFEPalmAttributes *out_attributes)
Calculate palm image quality attributes from given source image and palm detection.
float y
Y coordinate of the top left corner of the bounding box relative to source image size - range <0,...
float width
Width of the bounding box relative to source image size - range <0,1>
float x
X coordinate of the top left corner of the bounding box relative to source image size - range <0,...
float height
Height of the bounding box relative to source image size - range <0,1>
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.
float quality
Range <0, 1>. The recommended threshold for further palm processing is 0.6.
Palm landmarks (keypoints, hand position, orientation, confidence)
SFEPalmKeypoint keypoints[SFE_PALM_KEYPOINT_COUNT]
Palm keypoints.
SFEHandPosition hand_position
Detected hand position.
SFEHandOrientation hand_orientation
Detected palm orientation.