11#include "enrollment/Export.h"
13#include <shared_mutex>
14#include <unordered_map>
20 INNO_ENROLLMENT_API
void* inno_local_IndexedModalitiesGallery_Create(inno_Deleter* deleter,
22 uint64_t threadsCount,
23 ErrorCallbacks errorCallbacks);
24 INNO_ENROLLMENT_API
void inno_local_IndexedModalitiesGallery_CheckPrintTemplate(
void* gallery,
26 ErrorCallbacks errorCallbacks);
27 INNO_ENROLLMENT_API
void inno_local_IndexedModalitiesGallery_CheckFaceTemplate(
void* gallery,
29 ErrorCallbacks errorCallbacks);
30 INNO_ENROLLMENT_API
void inno_local_IndexedModalitiesGallery_CheckIrisTemplate(
void* gallery,
32 ErrorCallbacks errorCallbacks);
33 INNO_ENROLLMENT_API
void inno_local_IndexedModalitiesGallery_ReferenceAdd(
void* gallery,
35 inno_Template* prints,
39 inno_Template* irises,
41 ErrorCallbacks errorCallbacks);
42 INNO_ENROLLMENT_API
void inno_local_IndexedModalitiesGallery_ReferenceRemove(
void* gallery,
44 ErrorCallbacks errorCallbacks);
45 using inno_AllocateIds =
size_t* (*)(
void*,
size_t);
46 INNO_ENROLLMENT_API
void inno_local_IndexedModalitiesGallery_CandidateFind(
void* gallery,
47 inno_Template* prints,
51 inno_Template* irises,
53 inno_AllocateIds allocator,
54 void* printsCandidates,
55 void* facesCandidates,
56 void* irisesCandidates,
57 size_t bestCandidatesCount,
58 ErrorCallbacks errorCallbacks);
127 " of IndexedModalitiesGallery is unknown");
147 writer.Write(
"tc", threads);
148 writer.Write(
"t",
static_cast<int>(type));
159 static constexpr unsigned int DefaultThreads = 1;
160 unsigned int threads = DefaultThreads;
201 class IndexedModalitiesGallery
214 return std::shared_ptr<IndexedModalitiesGallery>(
new IndexedModalitiesGallery(std::move(config)));
240 virtual void Add(
Identifier identifier,
const std::shared_ptr<ModalitiesTemplate>& templ)
242 if (templ ==
nullptr)
247 auto [prints, faces, irises] = ConvertToInnoTemplates(templ);
249 inno_local_IndexedModalitiesGallery_ReferenceAdd(impl.get(),
268 inno_local_IndexedModalitiesGallery_ReferenceRemove(impl.get(), identifier, ThrowOnError{});
274 class ModalitiesIdentifiers
305 ModalitiesIdentifiers(std::vector<Identifier> ps, std::vector<Identifier> fs, std::vector<Identifier> is)
306 : prints(std::move(ps))
307 , faces(std::move(fs))
308 , irises(std::move(is))
311 ModalitiesIdentifiers() =
delete;
314 std::vector<Identifier> prints;
315 std::vector<Identifier> faces;
316 std::vector<Identifier> irises;
342 const std::shared_ptr<ModalitiesTemplate>& probe,
343 size_t maxCandidates)
const
345 auto [prints, faces, irises] = ConvertToInnoTemplates(probe);
347 std::vector<Identifier> printIds;
348 std::vector<Identifier> faceIds;
349 std::vector<Identifier> irisIds;
350 auto idsAllocator = +[](
void* container,
size_t length) ->
size_t*
352 std::vector<Identifier>& vec = *
static_cast<std::vector<Identifier>*
>(container);
357 inno_local_IndexedModalitiesGallery_CandidateFind(impl.get(),
371 return std::make_shared<ModalitiesIdentifiers>(std::move(printIds), std::move(faceIds), std::move(irisIds));
384 : c(std::move(config))
385 , impl(CreateImpl(c.GetGalleryType(), c.GetThreadCount()))
390 [[nodiscard]] std::tuple<std::vector<inno_Template>, std::vector<inno_Template>, std::vector<inno_Template>>
391 ConvertToInnoTemplates(
const std::shared_ptr<ModalitiesTemplate>& tmpl)
const
395 throw NullArgumentException(
"Null template cannot be processed by gallery");
397 auto printTemplates = tmpl->GetPrintTemplates();
400 : inno_Template::FromTemplates(PrintTemplate::ToICSTemplates(printTemplates));
401 std::for_each(prints.begin(),
404 { inno_local_IndexedModalitiesGallery_CheckPrintTemplate(impl.get(), t, ThrowOnError{}); });
406 auto faceTemplates = tmpl->GetFaceTemplates();
407 auto faces = inno_Template::FromTemplates(faceTemplates);
408 std::for_each(faces.begin(),
411 { inno_local_IndexedModalitiesGallery_CheckFaceTemplate(impl.get(), t, ThrowOnError{}); });
413 auto irisTemplates = tmpl->GetIrisTemplates();
414 auto irises = inno_Template::FromTemplates(irisTemplates);
415 std::for_each(irises.begin(),
418 { inno_local_IndexedModalitiesGallery_CheckIrisTemplate(impl.get(), t, ThrowOnError{}); });
420 return { prints, faces, irises };
425 inno_Deleter deleter = {};
427 auto* i = inno_local_IndexedModalitiesGallery_Create(
428 &deleter,
static_cast<uint8_t
>(type),
static_cast<uint64_t
>(threadsCount), ThrowOnError{});
430 return { i, deleter };
433 std::unique_ptr<void, inno_Deleter> impl;
IndexedModalitiesGalleryType
Type of IndexedModalitiesGallery.
Definition IndexedModalitiesGallery.h:64
@ PRINT_EMBEDDING
The gallery identification of candidates is based on print EmbeddingTemplate.
Definition IndexedModalitiesGallery.h:72
@ PRINT_ICS_TEMPLATE
The gallery identification of candidates is based on print ICSTemplate.
Definition IndexedModalitiesGallery.h:67
Base exception for all enrollment-sdk invalid argument exceptions.
Definition EnrollmentException.h:96
IndexedModalitiesGallery configuration.
Definition IndexedModalitiesGallery.h:80
void WriteTo(Writer &writer) const final
Function serializes configuration via provided Writer.
Definition IndexedModalitiesGallery.h:144
IndexedModalitiesGalleryConfig()=default
Default configuration is.
IndexedModalitiesGalleryType GetGalleryType() const
Get type of Modalities Gallery.
Definition IndexedModalitiesGallery.h:135
void SetGalleryType(IndexedModalitiesGalleryType value)
Set type of Modalities Gallery.
Definition IndexedModalitiesGallery.h:116
unsigned int GetThreadCount() const
Get number of processing threads.
Definition IndexedModalitiesGallery.h:103
void SetThreadsCount(unsigned int value)
Set number of threads used by gallery.
Definition IndexedModalitiesGallery.h:89
Contains candidates per each modality.
Definition IndexedModalitiesGallery.h:274
std::vector< Identifier > GetPrintIdentifiers() const
Returns best candidates for print modality.
Definition IndexedModalitiesGallery.h:281
std::vector< Identifier > GetFaceIdentifiers() const
Returns best candidates for face modality.
Definition IndexedModalitiesGallery.h:290
std::vector< Identifier > GetIrisIdentifiers() const
Returns best candidates for iris modality.
Definition IndexedModalitiesGallery.h:299
Gallery of references identifiers.
Definition IndexedModalitiesGallery.h:201
virtual std::shared_ptr< ModalitiesIdentifiers > IdentifyModalities(const std::shared_ptr< ModalitiesTemplate > &probe, size_t maxCandidates) const
Search for given probe.
Definition IndexedModalitiesGallery.h:340
virtual void Remove(Identifier identifier)
Removes reference template under provided index identifier from the gallery.
Definition IndexedModalitiesGallery.h:265
size_t Identifier
Index identifier of reference in gallery.
Definition IndexedModalitiesGallery.h:204
virtual void Add(Identifier identifier, const std::shared_ptr< ModalitiesTemplate > &templ)
Adds reference template under index identifier into gallery.
Definition IndexedModalitiesGallery.h:239
static std::shared_ptr< IndexedModalitiesGallery > Create(IndexedModalitiesGalleryConfig config)
Create indexed gallery of references.
Definition IndexedModalitiesGallery.h:211
Null argument is not allowed.
Definition EnrollmentException.h:156
static std::vector< std::shared_ptr< EmbeddingTemplate > > ToEmbeddingTemplates(const std::vector< std::shared_ptr< PrintTemplate > > &templates)
Converts a PrintTemplate objects into an EmbeddingTemplate objects.
Definition PrintTemplate.h:58
Provides interface for serialization of all classes.
Definition Writer.h:164