Enrollment 28.2.0
Loading...
Searching...
No Matches
ICSExtractor.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "enrollment/Export.h"
22#include <array>
23#include <functional>
24#include <vector>
25
26namespace inno
27{
28 class Logger;
29
34 */
35 class ICSExtractor
36 {
37 public:
41 */
42 class Artifact
43 {
44 private:
51 virtual void ConfigureExtractionParameters(const std::shared_ptr<Print>& print,
52 inno_ICSExtractor_params& params) = 0;
56 virtual void OnCreated() = 0;
62 virtual void CheckCompatibility(inno_ICSExtractor_params& params) = 0;
63
64 public:
65 Artifact() = default;
66 Artifact(const Artifact&) = delete;
67 Artifact(Artifact&&) = delete;
68 Artifact& operator=(const Artifact&) = delete;
69 Artifact& operator=(Artifact&& c) = delete;
70 virtual ~Artifact() = default;
71
72 friend class ICSExtractor;
73 };
74
77 */
78 class Artifacts : public Artifact
79 {
80 public:
88 */
89 void Add(Artifact& artifact)
90 {
91 const std::lock_guard lock(artifactsMux);
92
93 if (isExtractionInProgress)
94 {
95 throw EnrollmentRuntimeException("cannot add artifact during extraction");
96 }
97
98 inno_ICSExtractor_params param = {};
99
100 for (auto* a : artifacts)
101 {
102 a->CheckCompatibility(param);
103 }
104
105 // when not compatible then it will throw
106 artifact.CheckCompatibility(param);
107
108 artifacts.emplace_back(&artifact);
109 }
110
111 private:
118 void ConfigureExtractionParameters(const std::shared_ptr<Print>& print,
119 inno_ICSExtractor_params& params) final
120 {
121 const std::lock_guard lock(artifactsMux);
122
123 for (auto* a : artifacts)
124 {
125 a->ConfigureExtractionParameters(print, params);
126 }
127
128 isExtractionInProgress = true;
129 }
133 void OnCreated() final
134 {
135 const std::lock_guard lock(artifactsMux);
136
137 for (auto* a : artifacts)
138 {
139 a->OnCreated();
140 }
141
142 isExtractionInProgress = false;
143 }
144
150 void CheckCompatibility(inno_ICSExtractor_params& params) final
151 {
152 const std::lock_guard lock(artifactsMux);
153
154 for (auto* a : artifacts)
155 {
156 a->CheckCompatibility(params);
157 }
158 }
159
160 std::vector<Artifact*> artifacts;
161 std::mutex artifactsMux;
162 bool isExtractionInProgress = false;
163
164 public:
165 Artifacts() = default;
166 Artifacts(const Artifacts&) = delete;
167 Artifacts(Artifacts&&) = delete;
168 Artifacts& operator=(const Artifacts&) = delete;
169 Artifacts& operator=(Artifacts&& c) = delete;
170 virtual ~Artifacts() = default;
171 };
172
181 */
182 class SkeletonImage : public Artifact
183 {
184 public:
190 */
191 [[nodiscard]] std::shared_ptr<Image> GetImage() const
192 {
193 if (image == nullptr)
194 {
195 throw EnrollmentRuntimeException("skeleton image is not available");
196 }
197 return image;
198 }
199
205 */
206 [[nodiscard]] std::shared_ptr<Image> DrawMinutiae(const std::vector<std::shared_ptr<Minutia>>& minutiae,
207 const ImageShapeAttributes& attr) const
208 {
209 return image->DrawShape(MinutiaeShape(minutiae, attr));
210 }
211
217 */
218 [[nodiscard]] std::shared_ptr<Image> DrawCriticalPoints(
219 const std::vector<std::shared_ptr<CriticalPoint>>& points,
220 const ImageShapeAttributes& attr) const
221 {
222 return image->DrawShape(CriticalPointsShape(points, attr));
223 }
224
225 SkeletonImage() = default;
226 SkeletonImage(const SkeletonImage&) = delete;
227 SkeletonImage(SkeletonImage&&) = delete;
228 SkeletonImage& operator=(const SkeletonImage&) = delete;
229 SkeletonImage& operator=(SkeletonImage&& c) = delete;
230 virtual ~SkeletonImage() = default;
231
232 private:
233 ImageWidth width = 0;
234 ImageHeight height = 0;
235 ImageDpi dpi = DefaultDpi;
236 std::shared_ptr<ImageEncoder> encoder;
237 std::vector<uint8_t> data;
238 std::shared_ptr<Image> image;
239
240 void ConfigureExtractionParameters(const std::shared_ptr<Print>& print,
241 inno_ICSExtractor_params& params) final
242 {
243 width = print->image->Width();
244 height = print->image->Height();
245 dpi = print->image->Dpi();
246 encoder = print->image->OriginalEncoder();
247
248 data.resize(static_cast<size_t>(height) * static_cast<size_t>(width));
249
250 params.skeletonImage = data.data();
251 }
252
253 void OnCreated() final
254 {
255 image =
256 Image::DecodeRawImage(RawImage{ width, height, dpi, RawImage::GRAYSCALE, std::move(data) }, encoder);
257 }
258 void CheckCompatibility(inno_ICSExtractor_params& params) final
259 {
260 if (params.skeletonImage != nullptr)
261 {
262 throw EnrollmentRuntimeException("skeleton artifact is already enabled");
263 }
264 static unsigned char c = 0;
265 params.skeletonImage = &c;
266 }
267 };
268
277 */
278 class FilteredImage : public Artifact
279 {
280 public:
286 */
287 [[nodiscard]] std::shared_ptr<Image> GetImage() const
288 {
289 if (image == nullptr)
290 {
291 throw EnrollmentRuntimeException("filtered image is not available");
292 }
293 return image;
294 }
295
296 FilteredImage() = default;
297 FilteredImage(const FilteredImage&) = delete;
298 FilteredImage(FilteredImage&&) = delete;
299 FilteredImage& operator=(const FilteredImage&) = delete;
300 FilteredImage& operator=(FilteredImage&& c) = delete;
301 virtual ~FilteredImage() = default;
302
303 private:
304 ImageWidth width = 0;
305 ImageHeight height = 0;
306 ImageDpi dpi = DefaultDpi;
307 std::shared_ptr<ImageEncoder> encoder;
308 std::vector<uint8_t> data;
309 std::shared_ptr<Image> image;
310
311 void ConfigureExtractionParameters(const std::shared_ptr<Print>& print,
312 inno_ICSExtractor_params& params) final
313 {
314 width = print->image->Width();
315 height = print->image->Height();
316 dpi = print->image->Dpi();
317 encoder = print->image->OriginalEncoder();
318
319 data.resize(static_cast<size_t>(height) * static_cast<size_t>(width));
320
321 params.filteredImage = data.data();
322 }
323
324 void OnCreated() final
325 {
326 image =
327 Image::DecodeRawImage(RawImage{ width, height, dpi, RawImage::GRAYSCALE, std::move(data) }, encoder);
328 }
329
330 void CheckCompatibility(inno_ICSExtractor_params& params) final
331 {
332 if (params.filteredImage != nullptr)
333 {
334 throw EnrollmentRuntimeException("filtered artifact is already enabled");
335 }
336
337 static unsigned char c = 0;
338 params.filteredImage = &c;
339 }
340 };
341
350 */
351 class BinarizedImage : public Artifact
352 {
353 public:
359 */
360 [[nodiscard]] std::shared_ptr<Image> GetImage() const
361 {
362 if (image == nullptr)
363 {
364 throw EnrollmentRuntimeException("binarized image is not available");
365 }
366 return image;
367 }
368
369 BinarizedImage() = default;
370 BinarizedImage(const BinarizedImage&) = delete;
371 BinarizedImage(BinarizedImage&&) = delete;
372 BinarizedImage& operator=(const BinarizedImage&) = delete;
373 BinarizedImage& operator=(BinarizedImage&& c) = delete;
374 virtual ~BinarizedImage() = default;
375
376 private:
377 ImageWidth width = 0;
378 ImageHeight height = 0;
379 ImageDpi dpi = DefaultDpi;
380 std::shared_ptr<ImageEncoder> encoder;
381 std::vector<uint8_t> data;
382 std::shared_ptr<Image> image;
383
384 void ConfigureExtractionParameters(const std::shared_ptr<Print>& print,
385 inno_ICSExtractor_params& params) final
386 {
387 width = print->image->Width();
388 height = print->image->Height();
389 dpi = print->image->Dpi();
390 encoder = print->image->OriginalEncoder();
391
392 data.resize(static_cast<size_t>(height) * static_cast<size_t>(width));
393
394 params.binarizedImage = data.data();
395 }
396
397 void OnCreated() final
398 {
399 image =
400 Image::DecodeRawImage(RawImage{ width, height, dpi, RawImage::GRAYSCALE, std::move(data) }, encoder);
401 }
402
403 void CheckCompatibility(inno_ICSExtractor_params& params) final
404 {
405 if (params.binarizedImage != nullptr)
406 {
407 throw EnrollmentRuntimeException("binarized artifact is already enabled");
408 }
409
410 static unsigned char c = 0;
411 params.binarizedImage = &c;
412 }
413 };
414
424 */
425 std::shared_ptr<ExtractedPrint> Extract(std::shared_ptr<Print> print, Artifact& artifact)
426 {
427 if (print == nullptr)
428 {
429 throw NullArgumentException("Print can not be null");
430 }
431
432 log.LogInfo("Print extraction for %v ...", print);
433
434 uint8_t* outTemplate = nullptr;
435 unsigned int outTemplateSize = 0;
436 const CallbackLogger slog(log.GetLogger());
437 inno_ICSExtractor_params params = {};
438 auto gs = print->image->AsRawGrayscale();
439 params.height = gs.height;
440 params.width = gs.width;
441 params.data = gs.Data().data();
442 params.dpi = static_cast<unsigned int>(gs.dpi);
443
444 artifact.ConfigureExtractionParameters(print, params);
445
446 exec->Extract(&params, slog.GetCallbacks(), &outTemplate, &outTemplateSize, ThrowOnError{});
447
448 artifact.OnCreated();
449
450 std::vector<uint8_t> templateData(outTemplate, std::next(outTemplate, outTemplateSize));
451 exec->FreeTemplate(outTemplate, outTemplateSize);
452
453 auto extractedPrint = std::make_shared<ExtractedPrint>(std::move(templateData), std::move(print), exec);
454 log.LogInfo("Print extraction result %v", extractedPrint);
455
456 return extractedPrint;
457 }
458
467 */
468 std::shared_ptr<ExtractedPrint> Extract(const std::shared_ptr<Print>& print)
469 {
470 auto nullArtifact = NullArtifact();
471 return Extract(print, nullArtifact);
472 }
476 */
478 : log(GlobalLogger::Get())
479 , exec(GlobalPrintExecutor::Get())
480 {
481 }
482
487 */
488 explicit ICSExtractor(std::shared_ptr<PrintExecutor> executor)
489 : log(GlobalLogger::Get())
490 , exec(std::move(executor))
491 {
492 if (exec == nullptr)
493 {
494 throw NullArgumentException("executor can not be null");
495 }
496 }
497 ICSExtractor(const ICSExtractor&) = delete;
498 ICSExtractor(ICSExtractor&&) = delete;
499 ICSExtractor& operator=(const ICSExtractor&) = delete;
500 ICSExtractor& operator=(ICSExtractor&&) = delete;
501 virtual ~ICSExtractor() = default;
502
503 private:
504 class NullArtifact final : public Artifact
505 {
506 private:
507 void ConfigureExtractionParameters(const std::shared_ptr<Print>& /*print*/,
508 inno_ICSExtractor_params& /*params*/) final
509 {
510 }
511 void OnCreated() final
512 {
513 }
514 void CheckCompatibility(inno_ICSExtractor_params& /*params*/) final
515 {
516 }
517
518 public:
519 NullArtifact() = default;
520 NullArtifact(const NullArtifact&) = delete;
521 NullArtifact(NullArtifact&&) = delete;
522 NullArtifact& operator=(const NullArtifact&) = delete;
523 NullArtifact& operator=(NullArtifact&& c) = delete;
524 virtual ~NullArtifact() = default;
525 };
526
527 FormattingLogger log;
528 std::shared_ptr<PrintExecutor> exec;
529 };
530} // namespace inno
constexpr ImageDpi DefaultDpi
Provides default DPI Default DPI is 500.
Definition ImageAttribute.h:107
CallbackLogger is logger for binary part of libary due to C boundary.
Definition Logger.h:157
LoggerCallBacks GetCallbacks() const
Get the Callbacks object.
Definition Logger.h:166
It draws collection of CriticalPoint into image.
Definition CriticalPoint.h:181
Base exception for all enrollment-sdk runtime exceptions.
Definition EnrollmentException.h:84
Holds instance of Logger.
Definition Logger.h:275
Holds instance of PrintExecutor.
Definition PrintExecutor.h:1300
Interface that generalize storing of intermediate images and other artifacts that are produced during...
Definition ICSExtractor.h:42
void Add(Artifact &artifact)
Add artifact to be created during extraction.
Definition ICSExtractor.h:88
It enables creation of binarized image during extraction.
Definition ICSExtractor.h:351
std::shared_ptr< Image > GetImage() const
Get created Image To create Image, extraction must be finished.
Definition ICSExtractor.h:359
It enables creation of filtered image during extraction.
Definition ICSExtractor.h:278
std::shared_ptr< Image > GetImage() const
Get created Image To create Image, extraction must be finished.
Definition ICSExtractor.h:286
It enables creation of skeleton image during extraction.
Definition ICSExtractor.h:182
std::shared_ptr< Image > DrawMinutiae(const std::vector< std::shared_ptr< Minutia > > &minutiae, const ImageShapeAttributes &attr) const
Draws minutiae on skeleton image.
Definition ICSExtractor.h:205
std::shared_ptr< Image > GetImage() const
Get created Image To create Image, extraction must be finished.
Definition ICSExtractor.h:190
std::shared_ptr< Image > DrawCriticalPoints(const std::vector< std::shared_ptr< CriticalPoint > > &points, const ImageShapeAttributes &attr) const
Draws critical points on skeleton image.
Definition ICSExtractor.h:217
ICSExtractor creates ICS, Innovatrics proprietary print template.
Definition ICSExtractor.h:35
std::shared_ptr< ExtractedPrint > Extract(std::shared_ptr< Print > print, Artifact &artifact)
Function creates ICS template for given Print.
Definition ICSExtractor.h:424
std::shared_ptr< ExtractedPrint > Extract(const std::shared_ptr< Print > &print)
Function creates ICS template for given Print.
Definition ICSExtractor.h:467
ICSExtractor()
Constructs new ICSExtractor.
Definition ICSExtractor.h:476
ICSExtractor(std::shared_ptr< PrintExecutor > executor)
Constructs new ICSExtractor.
Definition ICSExtractor.h:487
Image DPI.
Definition ImageAttribute.h:47
It holds shape attributes such as color and line width.
Definition ImageShape.h:22
static std::shared_ptr< Image > DecodeRawImage(const RawImage &raw, std::shared_ptr< ImageEncoder > originalEncoder=nullptr, std::shared_ptr< ImageExecutor > executor=GlobalImageExecutor::Get())
Creates Image from raw data.
Definition Image.h:200
Interface for library logging.
Definition Logger.h:45
It draws Minutia into image.
Definition Minutia.h:188
Null argument is not allowed.
Definition EnrollmentException.h:156
Contains plain image data.
Definition ImageAttribute.h:135
@ GRAYSCALE
Raw data where image pixels are stored in grayscale format.
Definition ImageAttribute.h:146
ImageDimension ImageHeight
Image Height.
Definition ImageAttribute.h:36
ImageDimension ImageWidth
Image Width.
Definition ImageAttribute.h:41