SmartFace Embedded Toolkit  4.2.1
Loading...
Searching...
No Matches
example_tattoo_detect.cpp File Reference
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <vector>
#include <sfe_toolkit/sfe_core.h>
#include <sfe_toolkit/sfe_tattoo.h>
#include "annotate.hpp"
#include "solvers.h"
#include "utils.hpp"
#include "optional"

Go to the source code of this file.

Functions

int main ()
 

Variables

const auto SOLVER_PARAMETERS
 
std::string image_path = "assets/tattoo/tattoo_0.png"
 
std::optional< std::string > solver = std::nullopt
 

Function Documentation

◆ main()

int main ( )

[Tattoo Detect]

[Tattoo Detect]

Definition at line 26 of file example_tattoo_detect.cpp.

26 {
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

Variable Documentation

◆ image_path

std::string image_path = "assets/tattoo/tattoo_0.png"

Definition at line 19 of file example_tattoo_detect.cpp.

◆ solver

std::optional<std::string> solver = std::nullopt

Definition at line 23 of file example_tattoo_detect.cpp.

◆ SOLVER_PARAMETERS

const auto SOLVER_PARAMETERS
Initial value:
= std::vector<SFESolverParameter>{
SFESolverParameter{"intra_threads", "4"},
}
Solver parameter used to configure solvers.
Definition sfe_core.h:105

Definition at line 15 of file example_tattoo_detect.cpp.