#include "sfe_toolkit/sfe_core.h"
#include "sfe_toolkit/sfe_iris.h"
#include <regex>
#include <vector>
#include <iomanip>
#include <sstream>
#include "annotate.hpp"
#include "solvers.h"
#include "utils.hpp"
#include <unordered_map>
{
utils::checkError(error);
}
size_t iris_count = 1;
{
error =
sfeDetect(detector_solver, image, 0.1f, &detected_iris, &iris_count);
utils::checkError(error);
if (iris_count == 0 || detected_iris.
confidence < 0.5) {
throw std::runtime_error("No iris detected in the probe image.");
}
std::cout << "Found iris in the image. Extracting template..." << std::endl;
}
{
&iris_template);
utils::checkError(error);
}
return iris_template;
}
std::cout << "Help: Usage of the program." << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-h: Display help." << std::endl;
std::cout << "-p: Probe image file." << std::endl;
std::cout << "-g: Matching image file. Our \"iris database\"." << std::endl;
std::cout << "-d: Path to detector solver." << std::endl;
std::cout << "-e: Path to extraction solver." << std::endl;
std::cout << "-t: Detection threshold. <0,1>" << std::endl;
std::cout << "-i: Identification threshold. <0,1>" << std::endl;
}
int main(
int argc,
char *argv[]) {
{
std::unordered_map<std::string, std::string> args;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg[0] == '-') {
if (arg == "-h") {
return 0;
}
if (i + 1 < argc && argv[i + 1][0] != '-') {
args[arg] = argv[++i];
} else {
std::cerr << "Option " << arg << " requires a value." << std::endl;
return 1;
}
} else {
std::cerr << "Unknown option: " << arg << std::endl;
return 1;
}
}
if (args.count("-p"))
if (args.count("-g"))
if (args.count("-d"))
if (args.count("-e"))
if (args.count("-i"))
utils::printFormatted("EXAMPLE PARAMETERS");
std::cout <<
"Probe image: " <<
image_probe << std::endl;
std::cout <<
"Matching image: " <<
image_match << std::endl;
<< std::endl;
}
utils::printToolkitInfo();
{
utils::printFormatted("LOADING SOLVERS");
utils::checkError(error);
utils::checkError(error);
}
{
utils::printFormatted("PROBE TEMPLATE EXTRACTION");
probe_iris_template =
}
{
utils::printFormatted("PROBE TEMPLATE ATTRIBUTES");
utils::checkError(error);
std::cout <<
"Version of the probe template: " << version.
version_major
float quality = {};
utils::checkError(error);
std::cout << "Quality of the probe template: " << quality << std::endl;
}
size_t gallery_size = 10;
std::vector<SFEIrisTemplate> iris_template_gallery(gallery_size);
{
utils::printFormatted("IRIS GALLERY EXTRACTION");
auto matching_iris_template =
auto non_matching_iris_template =
for (size_t i = 0; i < gallery_size; i++) {
iris_template_gallery[i] = non_matching_iris_template;
}
iris_template_gallery[5] = matching_iris_template;
}
size_t candidate_count = 1;
std::vector<SFETemplateIdentificationCandidate> identification_results(
candidate_count);
{
utils::printFormatted("1:N IDENTIFICATION");
&probe_iris_template, iris_template_gallery.data(),
identification_results.data(), &candidate_count, 4);
utils::checkError(error);
if (candidate_count == 0) {
std::cout << "No candidates found above identification threshold "
return 0;
}
std::cout << "Found " << identification_results.size()
<< " candidates above identification threshold "
for (auto &result : identification_results)
std::cout << "Template index: #" << result.index
<< ", score: " << result.score << std::endl;
}
{
utils::printFormatted("1:1 MATCHING");
if (identification_results.size() == 0) {
std::cout << "No candidates found above identification threshold "
return 0;
}
auto match_iris_template =
iris_template_gallery[identification_results[0].index];
float match_confidence;
&match_confidence);
utils::checkError(error);
std::cout
<< "Matching score of probe template with the best template, score: "
<< match_confidence << std::endl;
}
utils::printFormatted("FINISHED");
}
float identification_threshold
const auto SOLVER_PARAMETERS
SFEIrisTemplate extract_template(std::string image_path, SFESolver &detector_solver, SFESolver &template_solver)
std::string solver_iris_detect
Solvers to use in example, the defaults are filled in by CMake.
std::string solver_iris_template
std::string image_non_match
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 sfeIrisTemplateMatch(const SFEIrisTemplate *template1, const SFEIrisTemplate *template2, float *out_matching_score)
Match two iris templates.
SFEError sfeIrisTemplateIdentify(const SFEIrisTemplate *probe_iris_template, const SFEIrisTemplate *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 sfeIrisTemplateVersion(const SFEIrisTemplate *iris_template, SFEIrisTemplateVersion *out_iris_template_version)
Get iris template version.
SFEError sfeIrisTemplateExtract(SFESolver solver, SFEImageView image, const SFEDetection *detection, SFEIrisTemplate *out_iris_template)
Extract template from source image and given iris detection.
SFEError sfeIrisTemplateQuality(const SFEIrisTemplate *iris_template, float *out_iris_template_quality)
Get iris template quality.
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.
Iris template version struct.
uint8_t version_major
Major template version.
uint8_t version_minor
Minor template version.