Enrollment 28.2.0
Loading...
Searching...
No Matches
ModalitiesEmbeddingVerifyMatcher.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "enrollment/Export.h"
20#include <array>
21#include <memory>
22#include <mutex>
23#include <unordered_map>
24#include <vector>
25
26namespace inno
27{
28 class Logger;
33 */
35 {
36 public:
46 */
48 const std::vector<std::shared_ptr<PrintTemplate>>& probe,
49 const std::vector<std::shared_ptr<PrintTemplate>>& gallery) const final
50 {
51 log.LogInfo("Matching embedding probe %v and gallery %v", probe, gallery);
52
53 auto probeEmbeddings = PrintTemplate::ToEmbeddingTemplates(probe);
54 auto galleryEmbeddings = PrintTemplate::ToEmbeddingTemplates(gallery);
55
56 using Position = int;
57 constexpr Position Unknown = -1;
58
59 std::unordered_map<Position, PrintSimilarityScore> scoreOnPosition;
60
61 for (const auto& pe : probeEmbeddings)
62 {
63 if (pe == nullptr)
64 {
65 continue;
66 }
67 std::optional<Position> probePos;
68 if (pe->IsEmbeddingTemplateBiometricPositionKnown())
69 {
70 probePos = static_cast<Position>(pe->GetEmbeddingTemplateBiometricPosition());
71 }
72 for (const auto& ge : galleryEmbeddings)
73 {
74 if (ge == nullptr)
75 {
76 continue;
77 }
78 std::optional<Position> galleryPos;
79 if (ge->IsEmbeddingTemplateBiometricPositionKnown())
80 {
81 galleryPos = static_cast<Position>(ge->GetEmbeddingTemplateBiometricPosition());
82 }
83 const bool probeIsUnknown = !probePos.has_value();
84 const bool galleryIsUnknown = !galleryPos.has_value();
85 if (probeIsUnknown || galleryIsUnknown || probePos == galleryPos)
86 {
87 const PrintSimilarityScore s = pe->SimilarWith(*ge, matcher);
88 const auto p = probePos.value_or(Unknown);
89 scoreOnPosition[p] = std::max(scoreOnPosition[p], s);
90 }
91 }
92 }
93 double scoreSum = 0;
94 for (const auto& [_, score] : scoreOnPosition)
95 {
96 scoreSum += score;
97 }
98 PrintSimilarityScore averageScore = 0;
99 if (!scoreOnPosition.empty())
100 {
101 averageScore =
102 static_cast<PrintSimilarityScore>(scoreSum / static_cast<double>(scoreOnPosition.size()));
103 }
104
105 log.LogInfo("Matching embedding probe %v and gallery %v with score %d", probe, gallery, averageScore);
106
107 return averageScore;
108 }
109
114 */
116 : log(GlobalLogger::Get())
117 , exec(GlobalMultiModalityExecutor::Get())
118 {
119 }
120
126 */
127 explicit ModalitiesEmbeddingVerifyMatcher(std::shared_ptr<MultiModalityExecutor> executor)
128 : log(GlobalLogger::Get())
129 , exec(std::move(executor))
130 {
131 if (exec == nullptr)
132 {
133 throw NullArgumentException("executor can not be null");
134 }
135 }
136
141 virtual ~ModalitiesEmbeddingVerifyMatcher() = default;
142
143 private:
145 std::shared_ptr<MultiModalityExecutor> exec;
147 };
148} // namespace inno
EmbeddingVerifyMatcher is template matcher that uses Innovatrics proprietary verification algorithm.
Definition EmbeddingVerifyMatcher.h:34
It provides functions with format specifier to compose and log message via provided Logger.
Definition FormattingLogger.h:601
Holds instance of Logger.
Definition Logger.h:275
Holds instance of MultiModalityExecutor.
Definition MultiModalityExecutor.h:434
Interface for library logging.
Definition Logger.h:45
ModalitiesEmbeddingVerifyMatcher is template matcher that uses Innovatrics proprietary verification a...
Definition ModalitiesEmbeddingVerifyMatcher.h:34
PrintSimilarityScore MatchPrints(const std::vector< std::shared_ptr< PrintTemplate > > &probe, const std::vector< std::shared_ptr< PrintTemplate > > &gallery) const final
Calculates prints similarity score of probe and gallery that contains only embedding prints.
Definition ModalitiesEmbeddingVerifyMatcher.h:46
ModalitiesEmbeddingVerifyMatcher(std::shared_ptr< MultiModalityExecutor > executor)
Constructor with custom executor.
Definition ModalitiesEmbeddingVerifyMatcher.h:126
ModalitiesEmbeddingVerifyMatcher()
Constructor with default logger and executor GlobalMultiModalityExecutor is used to execute matching.
Definition ModalitiesEmbeddingVerifyMatcher.h:114
ModalitiesVerifyMatcher()
Constructor with default Config GlobalMultiModalityExecutor is used to execute matching.
Definition ModalitiesVerifyMatcher.h:258
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
unsigned int PrintSimilarityScore
It is similarity score between print Templates.
Definition SimilarityScore.h:28