SmartFace Embedded Toolkit  4.2.1
Loading...
Searching...
No Matches
example_tattoo_detect.cpp
Go to the documentation of this file.
1#include <algorithm>
2#include <iomanip>
3#include <sstream>
4#include <vector>
5
6#include <sfe_toolkit/sfe_core.h>
7#include <sfe_toolkit/sfe_tattoo.h>
8
9#include "annotate.hpp"
10#include "solvers.h"
11#include "utils.hpp"
12#include "optional"
13
14// Solver parameters, we are using ONNX Runtime CPU backend
15const auto SOLVER_PARAMETERS = std::vector<SFESolverParameter>{
16 SFESolverParameter{"intra_threads", "4"},
17};
18
19std::string image_path = "assets/tattoo/tattoo_0.png";
20#ifdef SOLVER_TATTOO_DETECT
21std::optional<std::string> solver = SOLVER_TATTOO_DETECT;
22#else
23std::optional<std::string> solver = std::nullopt;
24#endif // SOLVER_TATTOO_DETECT
25
26int main() {
27 SFEError error;
28
29 SFEImage image{};
30 DEFER(sfeImageFree(image));
31 { // STAGE 1: Load Image
32 auto encoded_image = utils::readFile(image_path);
33 error = sfeImageDecode(encoded_image.data(), encoded_image.size(), &image);
34 utils::checkError(error);
35
36 std::cout << "Image size: " << image.width << "x" << image.height
37 << std::endl;
38 }
39
40 std::vector<SFEDetection> detections(10);
41 { // STAGE 2: Run person detection
42 // Initialize detection solver
43 SFESolver detection_solver{};
44 DEFER(sfeSolverFree(detection_solver));
46 error = sfeSolverCreate(
47 solver.value_or("").c_str(), SOLVER_PARAMETERS.data(), SOLVER_PARAMETERS.size(),
48 &detection_solver);
49 utils::checkError(error);
50
51 // Run detection for up to 10 tattoos
52 size_t detection_count = detections.size();
53 float detection_threshold = 0.3;
54 error = sfeDetect(detection_solver, image, detection_threshold,
55 detections.data(), &detection_count);
57 utils::checkError(error);
58 detections.resize(detection_count);
59
60 std::cout << "Detected " << detection_count << " tattoos" << std::endl;
61 }
62}
float detection_threshold
std::optional< std::string > solver
const auto SOLVER_PARAMETERS
std::string image_path
void sfeSolverFree(SFESolver solver)
Free memory associated with SFESolver.
void * SFESolver
Solver provides an abstract interface over inference models and engines.
Definition sfe_core.h:102
void * SFEError
Error type used to hold optional error message.
Definition sfe_core.h:97
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.
Raw owned raster image representation, HWC|BGR order.
Definition sfe_core.h:70
Solver parameter used to configure solvers.
Definition sfe_core.h:105