Enrollment 28.2.0
Loading...
Searching...
No Matches
ModalitiesVerifyMatcher.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "enrollment/Export.h"
18#include <array>
19#include <vector>
20
21namespace inno
22{
26 */
27 class ModalitiesVerifyMatcher : public ModalitiesMatcher
28 {
29 public:
32 */
33 class Config : public Serializable
34 {
35 public:
47 */
48 void SetMaxRotation(unsigned int value)
49 {
50 static constexpr unsigned int MaxRotation = 180;
51 if (value > MaxRotation)
52 {
53 throw EnrollmentInvalidArgumentException("Max rotation MUST be in range <0,180>");
54 }
55 maxRotation = value;
56 }
61 */
62 [[nodiscard]] unsigned int GetMaxRotation() const
63 {
64 return maxRotation;
65 }
69 */
70 void WriteTo(Writer& writer) const final
71 {
72 writer.Write("r", maxRotation);
73 }
74
80 */
81 static Config Default()
82 {
83 static const Config Cfg;
84 return Cfg;
85 }
86
91 Config() = default;
92 Config(const Config&) = default;
93 Config(Config&&) = default;
94 Config& operator=(const Config&) = default;
95 Config& operator=(Config&&) = default;
96 virtual ~Config() = default;
97
98 private:
99 static constexpr unsigned int DefaultMaxRotation = 180;
100 unsigned int maxRotation = DefaultMaxRotation;
101 };
102
111 */
112 [[nodiscard]] ModalityScore Match(const Applicant& probe, const Applicant& gallery) const final
113 {
114 log.LogInfo("Matching applicant probe %v and gallery %v with config %v", probe, gallery, cfg);
115 auto probeTemplate = probe.ToTemplate();
116 auto galleryTemplate = gallery.ToTemplate();
117 auto score = Match(*probeTemplate, *galleryTemplate);
118 log.LogInfo("Matching applicant probe %v and gallery %v with score %v", probe, gallery, score);
119 return score;
120 }
121
128 */
129 [[nodiscard]] ModalityScore Match(const ModalitiesTemplate& probe,
130 const ModalitiesTemplate& gallery) const final
131 {
132 log.LogInfo("Matching applicant template probe %v and gallery %v with config %v", probe, gallery, cfg);
133 auto score = ModalityScore{ MatchFaces(probe.GetFaceTemplates(), gallery.GetFaceTemplates()),
134 MatchIrises(probe.GetIrisTemplates(), gallery.GetIrisTemplates()),
135 MatchPrints(probe.GetPrintTemplates(), gallery.GetPrintTemplates()) };
136 log.LogInfo("Matching applicant template probe %v and gallery %v with score %v", probe, gallery, score);
137 return score;
138 }
139
147 */
148 [[nodiscard]] virtual PrintSimilarityScore MatchPrints(
149 const std::vector<std::shared_ptr<PrintTemplate>>& probe,
150 const std::vector<std::shared_ptr<PrintTemplate>>& gallery) const
151 {
152 int printScore = 0;
153 int dummyScore = 0;
154
155 const auto factory = ModalitiesICSTemplateDefaultFactory(exec);
156 const auto icsProbe = factory.CreateModalitiesICSTemplate(PrintTemplate::ToICSTemplates(probe), {}, {})
157 ->GetModalitiesICSTemplateData();
158 const auto icsGallery = factory.CreateModalitiesICSTemplate(PrintTemplate::ToICSTemplates(gallery), {}, {})
159 ->GetModalitiesICSTemplateData();
160
161 exec->Verify(log.GetLogger(),
162 icsProbe.data(),
163 icsProbe.size(),
164 icsGallery.data(),
165 icsGallery.size(),
166 cfg.GetMaxRotation(),
167 &printScore,
168 &dummyScore,
169 &dummyScore,
170 ThrowOnError{});
171
172 return static_cast<PrintSimilarityScore>(printScore);
173 }
174
182 */
183 [[nodiscard]] static FaceSimilarityScore MatchFaces(const std::vector<std::shared_ptr<FaceTemplate>>& probe,
184 const std::vector<std::shared_ptr<FaceTemplate>>& gallery)
185 {
186 FaceSimilarityScore faceScore = 0;
187 for (const auto& probeFace : probe)
188 {
189 for (const auto& galleryFace : gallery)
190 {
191 auto score = probeFace->SimilarWith(*galleryFace);
192 faceScore = std::max(faceScore, score);
193 }
194 }
195 return faceScore;
196 }
197
205 */
206 [[nodiscard]] static IrisSimilarityScore MatchIrises(const std::vector<std::shared_ptr<IrisTemplate>>& probe,
207 const std::vector<std::shared_ptr<IrisTemplate>>& gallery)
208 {
209 IrisSimilarityScore irisScore = 0;
210 IrisSimilarityScore irisLeftScore = 0;
211 IrisSimilarityScore irisRightScore = 0;
212 IrisSimilarityScore irisUnknownScore = 0;
213 unsigned int irisUnknownScoreCount = 0;
214 unsigned int irisLeftScoresCount = 0;
215 unsigned int irisRightScoresCount = 0;
216 for (const auto& probeIris : probe)
217 {
218 for (const auto& galleryIris : gallery)
219 {
220 if (probeIris->IsIrisTemplateBiometricPositionKnown() &&
221 galleryIris->IsIrisTemplateBiometricPositionKnown())
222 {
223 if (probeIris->GetIrisTemplateBiometricPosition() == IrisPosition::LEFT_EYE &&
224 galleryIris->GetIrisTemplateBiometricPosition() == IrisPosition::LEFT_EYE)
225 {
226 auto score = probeIris->SimilarWith(*galleryIris);
227 irisLeftScore = std::max(irisLeftScore, score);
228 irisLeftScoresCount = 1;
229 }
230 if (probeIris->GetIrisTemplateBiometricPosition() == IrisPosition::RIGHT_EYE &&
231 galleryIris->GetIrisTemplateBiometricPosition() == IrisPosition::RIGHT_EYE)
232 {
233 auto score = probeIris->SimilarWith(*galleryIris);
234 irisRightScore = std::max(irisRightScore, score);
235 irisRightScoresCount = 1;
236 }
237 }
238 else
239 {
240 auto score = probeIris->SimilarWith(*galleryIris);
241 irisUnknownScore += score;
242 irisUnknownScoreCount++;
243 }
244 }
245 }
246
247 if (auto scoresCount = irisUnknownScoreCount + irisLeftScoresCount + irisRightScoresCount; scoresCount != 0)
248 {
249 irisScore = (irisLeftScore + irisRightScore + irisUnknownScore) / scoresCount;
250 }
251
252 return irisScore;
253 }
254
258 */
260 : cfg(Config::Default())
261 , log(GlobalLogger::Get())
262 , exec(GlobalMultiModalityExecutor::Get())
263 {
264 }
265
270 */
271 explicit ModalitiesVerifyMatcher(Config config)
272 : cfg(std::move(config))
273 , log(GlobalLogger::Get())
274 , exec(GlobalMultiModalityExecutor::Get())
275 {
276 }
277
283 */
284 ModalitiesVerifyMatcher(Config config, std::shared_ptr<MultiModalityExecutor> executor)
285 : cfg(std::move(config))
286 , log(GlobalLogger::Get())
287 , exec(std::move(executor))
288 {
289 if (exec == nullptr)
290 {
291 throw NullArgumentException("executor can not be null");
292 }
293 }
294
301 */
303 std::shared_ptr<MultiModalityExecutor> executor,
304 std::shared_ptr<Logger> logger)
305 : cfg(std::move(config))
306 , log(std::move(logger))
307 , exec(std::move(executor))
308 {
309 if (exec == nullptr)
310 {
311 throw NullArgumentException("executor can not be null");
312 }
313 }
314
319 */
320 explicit ModalitiesVerifyMatcher(std::shared_ptr<MultiModalityExecutor> executor)
321 : cfg(Config::Default())
322 , log(GlobalLogger::Get())
323 , exec(std::move(executor))
324 {
325 if (exec == nullptr)
326 {
327 throw NullArgumentException("executor can not be null");
328 }
329 }
330
333 ModalitiesVerifyMatcher& operator=(const ModalitiesVerifyMatcher&) = delete;
335 virtual ~ModalitiesVerifyMatcher() = default;
336
337 private:
338 Config cfg;
340 std::shared_ptr<MultiModalityExecutor> exec;
341 };
342} // namespace inno
Applicant represent enrolled person.
Definition Applicant.h:255
Base exception for all enrollment-sdk invalid argument exceptions.
Definition EnrollmentException.h:96
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
ModalitiesICSTemplateDefaultFactory creates biometric representations from all modality templates.
Definition ModalitiesICSTemplateDefaultFactory.h:28
Applicant template in serialized form used for biometric operations.
Definition ModalitiesTemplate.h:54
ModalitiesVerifyMatcher configuration.
Definition ModalitiesVerifyMatcher.h:33
void WriteTo(Writer &writer) const final
Function serializes configuration via provided Writer.
Definition ModalitiesVerifyMatcher.h:69
void SetMaxRotation(unsigned int value)
Set the Max Rotation.
Definition ModalitiesVerifyMatcher.h:47
static Config Default()
Provides default config.
Definition ModalitiesVerifyMatcher.h:80
Config()=default
Default configuration is.
unsigned int GetMaxRotation() const
Get the Max Rotation.
Definition ModalitiesVerifyMatcher.h:61
ModalitiesVerifyMatcher is template matcher that uses Innovatrics proprietary verification algorithm.
Definition ModalitiesVerifyMatcher.h:27
static IrisSimilarityScore MatchIrises(const std::vector< std::shared_ptr< IrisTemplate > > &probe, const std::vector< std::shared_ptr< IrisTemplate > > &gallery)
Calculates face similarity score of probe and gallery that contains only irises.
Definition ModalitiesVerifyMatcher.h:205
ModalityScore Match(const ModalitiesTemplate &probe, const ModalitiesTemplate &gallery) const final
Calculates similarity score of probe and gallery applicant for each applicant modality.
Definition ModalitiesVerifyMatcher.h:128
ModalityScore Match(const Applicant &probe, const Applicant &gallery) const final
Calculates similarity score of probe and gallery applicant template for each modality.
Definition ModalitiesVerifyMatcher.h:111
ModalitiesVerifyMatcher()
Constructor with default Config GlobalMultiModalityExecutor is used to execute matching.
Definition ModalitiesVerifyMatcher.h:258
ModalitiesVerifyMatcher(Config config)
Constructor uses Config to setup matching algorithm.
Definition ModalitiesVerifyMatcher.h:270
ModalitiesVerifyMatcher(Config config, std::shared_ptr< MultiModalityExecutor > executor, std::shared_ptr< Logger > logger)
Constructor uses Config to setup matching algorithm.
Definition ModalitiesVerifyMatcher.h:301
static FaceSimilarityScore MatchFaces(const std::vector< std::shared_ptr< FaceTemplate > > &probe, const std::vector< std::shared_ptr< FaceTemplate > > &gallery)
Calculates face similarity score of probe and gallery that contains only faces.
Definition ModalitiesVerifyMatcher.h:182
virtual PrintSimilarityScore MatchPrints(const std::vector< std::shared_ptr< PrintTemplate > > &probe, const std::vector< std::shared_ptr< PrintTemplate > > &gallery) const
Calculates prints similarity score of probe and gallery that contains only prints.
Definition ModalitiesVerifyMatcher.h:147
ModalitiesVerifyMatcher(Config config, std::shared_ptr< MultiModalityExecutor > executor)
Constructor uses Config to setup matching algorithm.
Definition ModalitiesVerifyMatcher.h:283
ModalitiesVerifyMatcher(std::shared_ptr< MultiModalityExecutor > executor)
Constructor with default Config.
Definition ModalitiesVerifyMatcher.h:319
Contains scores of multiple modalities.
Definition SimilarityScore.h:75
Null argument is not allowed.
Definition EnrollmentException.h:156
static std::vector< std::shared_ptr< ICSTemplate > > ToICSTemplates(const std::vector< std::shared_ptr< PrintTemplate > > &templates)
Converts a PrintTemplate objects into a ICSTemplate objects.
Definition PrintTemplate.h:38
Provides interface for serialization of all classes.
Definition Writer.h:164
unsigned int FaceSimilarityScore
It is similarity score between face Templates.
Definition SimilarityScore.h:69
unsigned int IrisSimilarityScore
It is similarity score between iris Templates.
Definition SimilarityScore.h:40
@ RIGHT_EYE
Iris of right eye.
Definition IrisPosition.h:24
@ LEFT_EYE
Iris of left eye.
Definition IrisPosition.h:26
unsigned int PrintSimilarityScore
It is similarity score between print Templates.
Definition SimilarityScore.h:28