Enrollment 28.2.0
Loading...
Searching...
No Matches
PrintDetector.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "enrollment/Export.h"
21#include <memory>
22#include <vector>
23
24namespace inno
25{
29 */
30 class PrintDetectorConfig : public Serializable
31 {
32 public:
48 */
49 void SetNarrowFingerPreference(bool expectNarrow)
50 {
51 expectNarrowFinger = expectNarrow;
52 }
53
58 */
59 [[nodiscard]] bool GetNarrowFingerPreference() const
60 {
61 return expectNarrowFinger;
62 }
63
67 */
68 void WriteTo(Writer& writer) const override
69 {
70 writer.Write("enf", static_cast<int>(expectNarrowFinger));
71 }
72
77 PrintDetectorConfig() = default;
80 PrintDetectorConfig& operator=(const PrintDetectorConfig&) = default;
81 PrintDetectorConfig& operator=(PrintDetectorConfig&&) = default;
82 virtual ~PrintDetectorConfig() = default;
83
84 private:
85 bool expectNarrowFinger = true;
86 };
87
92 */
93 class PrintDetector : public PrintCaptureSegmentation
94 {
95 public:
105 */
106 std::vector<std::shared_ptr<PrintSegment>> Segment(const std::shared_ptr<PrintCapture>& capture) final
107 {
108
109 auto r = DoDetect(exec, capture->image, log);
110
111 std::vector<std::shared_ptr<PrintSegment>> res;
112
113 // We want to hide specific implementation of segmentation with all its details like types of 3rd-party
114 // libraries and its headers (Do not want to include it here and expose details). And we want to use the
115 // function in DLL where we cannot pass stl vector. Therefore the function will copy data.
116 for (unsigned int i = 0; i < r.count; i++)
117 {
118 const Rectangle roundingBox = {
119 { r.topLeftX[i], r.topLeftY[i] }, // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
120 { r.topRightX[i], r.topRightY[i] }, // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
121 { r.bottomRightX[i], // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
122 r.bottomRightY[i] }, // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
123 { r.bottomLeftX[i], r.bottomLeftY[i] } // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
124 };
125 res.emplace_back(std::make_shared<PrintSegment>(
126 capture,
127 capture->printAttributes,
128 roundingBox,
129 r.angle[i], // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
130 r.positions[i], // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
131 exec));
132 }
133 log.LogInfo("Print segmentation result %v", res);
134
135 return res;
136 }
137
141 */
143 : log(GlobalLogger::Get())
144 , exec(GlobalPrintExecutor::Get())
145 {
146 }
147
152 */
153 explicit PrintDetector(std::shared_ptr<PrintExecutor> executor)
154 : log(GlobalLogger::Get())
155 , exec(std::move(executor))
156
157 {
158 if (exec == nullptr)
159 {
160 throw NullArgumentException("executor can not be null");
161 }
162 }
163
164 PrintDetector(const PrintDetector&) = delete;
165 PrintDetector(PrintDetector&&) = delete;
166 PrintDetector& operator=(const PrintDetector&) = delete;
167 PrintDetector& operator=(PrintDetector&&) = delete;
168 virtual ~PrintDetector() = default;
169
170 protected:
178 virtual inno_PrintDetector_result DoDetect(const std::shared_ptr<PrintExecutor>& executor,
179 const std::shared_ptr<Image>& image,
180 FormattingLogger& logger) = 0;
181
182 private:
184 std::shared_ptr<PrintExecutor> exec;
185 };
186
190 */
191 class AlgorithmicSegmentation final : public PrintDetector
192 {
193 public:
196 */
197 class Config : public PrintDetectorConfig
198 {
199 public:
203 */
204 void WriteTo(Writer& writer) const final
205 {
206 writer.Write("mr", maxRotation);
207 writer.Write("rn", static_cast<int>(reduceNoise));
209 }
210
217 */
218 void SetMaxRotation(unsigned int value)
219 {
220 static constexpr unsigned int MaxRotation = 45;
221 if (value > MaxRotation)
222 {
224 "Max rotation of fingers for AlgorithmicSegmentation MUST be in range <0,45>");
225 }
226 maxRotation = value;
227 }
228
233 */
234 [[nodiscard]] unsigned int GetMaxRotation() const
235 {
236 return maxRotation;
237 }
238
242 */
244 {
245 reduceNoise = true;
246 }
247
252 */
253 [[nodiscard]] bool IsNoiseReduction() const
254 {
255 return reduceNoise;
256 }
257
263 */
264 static Config Default()
265 {
266 static const Config Cfg;
267 return Cfg;
268 }
269
278 Config() = default;
279 Config(const Config&) = default;
280 Config(Config&&) = default;
281 Config& operator=(const Config&) = default;
282 Config& operator=(Config&&) = default;
283 virtual ~Config() = default;
284
285 private:
286 static constexpr unsigned int DefaultMaxRotation = 45;
287 unsigned int maxRotation = DefaultMaxRotation;
288 bool reduceNoise = false;
289 };
290
295 */
296 explicit AlgorithmicSegmentation(Config config)
297 : cfg(std::move(config))
298 {
299 }
300
304 AlgorithmicSegmentation() = default;
305
311 */
312 AlgorithmicSegmentation(Config config, std::shared_ptr<PrintExecutor> executor)
313 : PrintDetector(std::move(executor))
314 , cfg(std::move(config))
315
316 {
317 }
318
323 */
324 explicit AlgorithmicSegmentation(std::shared_ptr<PrintExecutor> executor)
325 : PrintDetector(std::move(executor))
326 , cfg(Config::Default())
327
328 {
329 }
330
333 AlgorithmicSegmentation& operator=(const AlgorithmicSegmentation&) = delete;
335 virtual ~AlgorithmicSegmentation() = default;
336
337 private:
338 Config cfg = Config::Default();
339
340 inno_PrintDetector_result DoDetect(const std::shared_ptr<PrintExecutor>& executor,
341 const std::shared_ptr<Image>& image,
342 FormattingLogger& logger) final
343 {
344 logger.LogInfo("Algorithmic segmentation of image %v and config %v", image, cfg);
345 auto gs = image->AsRawGrayscale();
346 return executor->AlgoSegment(gs.height,
347 gs.width,
348 static_cast<unsigned int>(gs.dpi),
349 gs.Data().data(),
350 cfg.GetMaxRotation(),
351 cfg.IsNoiseReduction(),
352 cfg.GetNarrowFingerPreference(),
353 ThrowOnError{});
354 }
355 };
356
360 */
361 class NeuralSegmentation final : public PrintDetector
362 {
363 public:
366 */
367 class Config : public PrintDetectorConfig
368 {
369 public:
373 */
374 void WriteTo(Writer& writer) const final
375 {
376 writer.Write("mr", maxRotation);
377 writer.Write("ct", confidenceThreshold);
379 }
380
387 */
388 void SetMaxRotation(unsigned int value)
389 {
390 static constexpr unsigned int MaxRotation = 45;
391 if (value > MaxRotation)
392 {
394 "Max rotation of fingers for NeuralSegmentation MUST be in range <0,45>");
395 }
396 maxRotation = value;
397 }
398
403 */
404 [[nodiscard]] unsigned int GetMaxRotation() const
405 {
406 return maxRotation;
407 }
408
415 */
416 void SetConfidenceThreshold(unsigned int value)
417 {
418 static constexpr unsigned int MaxConfidenceThreshold = 10000;
419 if (value > MaxConfidenceThreshold)
420 {
422 "Confidence threshold for NeuralSegmentation MUST be in range [0-10000]");
423 }
424 confidenceThreshold = value;
425 }
426
431 */
432 [[nodiscard]] unsigned int GetConfidenceThreshold() const
433 {
434 return confidenceThreshold;
435 }
436
442 */
443 static Config Default()
444 {
445 static const Config Cfg;
446 return Cfg;
447 }
448
457 Config() = default;
458 Config(const Config&) = default;
459 Config(Config&&) = default;
460 Config& operator=(const Config&) = default;
461 Config& operator=(Config&&) = default;
462 virtual ~Config() = default;
463
464 private:
465 static constexpr unsigned int DefaultMaxRotation = 45;
466 unsigned int maxRotation = DefaultMaxRotation;
467 static constexpr unsigned int DefaultConfidenceThreshold = 9000;
468 unsigned int confidenceThreshold = DefaultConfidenceThreshold;
469 };
470
475 */
476 explicit NeuralSegmentation(Config config)
477 : cfg(std::move(config))
478 {
479 }
480
483 */
485 : cfg(Config::Default())
486 {
487 }
488
494 */
495 NeuralSegmentation(Config config, std::shared_ptr<PrintExecutor> executor)
496 : PrintDetector(std::move(executor))
497 , cfg(std::move(config))
498 {
499 }
500
505 */
506 explicit NeuralSegmentation(std::shared_ptr<PrintExecutor> executor)
507 : PrintDetector(std::move(executor))
508 , cfg(Config::Default())
509 {
510 }
511
512 NeuralSegmentation(const NeuralSegmentation&) = delete;
514 NeuralSegmentation& operator=(const NeuralSegmentation&) = delete;
515 NeuralSegmentation& operator=(NeuralSegmentation&&) = delete;
516 virtual ~NeuralSegmentation() = default;
517
518 private:
519 Config cfg;
520
521 inno_PrintDetector_result DoDetect(const std::shared_ptr<PrintExecutor>& executor,
522 const std::shared_ptr<Image>& image,
523 FormattingLogger& logger) final
524 {
525 logger.LogInfo("Neural segmentation of image %v and config %v", image, cfg);
526 auto gs = image->AsRawGrayscale();
527 return executor->NeuralSegment(gs.height,
528 gs.width,
529 static_cast<unsigned int>(gs.dpi),
530 gs.Data().data(),
531 cfg.GetMaxRotation(),
532 cfg.GetConfidenceThreshold(),
533 cfg.GetNarrowFingerPreference(),
534 ThrowOnError{});
535 }
536 };
537} // namespace inno
Configuration for AlgorithmicSegmentation.
Definition PrintDetector.h:197
void WriteTo(Writer &writer) const final
Function serializes configuration via provided Writer.
Definition PrintDetector.h:203
void SetMaxRotation(unsigned int value)
It sets maximum rotation of fingers in the slap image.
Definition PrintDetector.h:217
void EnableNoiseReduction()
It enables noise reduction before segmentation.
Definition PrintDetector.h:242
bool IsNoiseReduction() const
It returns true when noise reduction before segmentation is enabled.
Definition PrintDetector.h:252
static Config Default()
Provides default config.
Definition PrintDetector.h:263
Config()=default
Constructs default configuration.
unsigned int GetMaxRotation() const
It gets maximum rotation of fingers in the slap image.
Definition PrintDetector.h:233
AlgorithmicSegmentation implements algorithmic segmentation from Innovatrics ISegLib library.
Definition PrintDetector.h:191
AlgorithmicSegmentation(Config config)
Construct a new AlgorithmicSegmentation object.
Definition PrintDetector.h:295
AlgorithmicSegmentation(Config config, std::shared_ptr< PrintExecutor > executor)
Construct a new AlgorithmicSegmentation object.
Definition PrintDetector.h:311
AlgorithmicSegmentation()=default
Construct a new Algorithmic Segmentation with default config.
AlgorithmicSegmentation(std::shared_ptr< PrintExecutor > executor)
Construct a new Algorithmic Segmentation with default config.
Definition PrintDetector.h:323
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 PrintExecutor.
Definition PrintExecutor.h:1300
Configuration for NeuralSegmentation.
Definition PrintDetector.h:367
void WriteTo(Writer &writer) const final
Function serializes configuration via provided Writer.
Definition PrintDetector.h:373
void SetConfidenceThreshold(unsigned int value)
It sets confidence threshold.
Definition PrintDetector.h:415
void SetMaxRotation(unsigned int value)
It sets maximum rotation of fingers in the slap image.
Definition PrintDetector.h:387
static Config Default()
Provides default config.
Definition PrintDetector.h:442
Config()=default
Constructs default configuration.
unsigned int GetConfidenceThreshold() const
It gets confidence threshold.
Definition PrintDetector.h:431
unsigned int GetMaxRotation() const
It gets maximum rotation of fingers in the slap image.
Definition PrintDetector.h:403
NeuralSegmentation implements segmentation based on neural network from Innovatrics ISegLib library.
Definition PrintDetector.h:361
NeuralSegmentation(Config config, std::shared_ptr< PrintExecutor > executor)
Construct a new NeuralSegmentation object.
Definition PrintDetector.h:494
NeuralSegmentation(std::shared_ptr< PrintExecutor > executor)
Construct a new NeuralSegmentation with default config.
Definition PrintDetector.h:505
NeuralSegmentation(Config config)
Construct a new NeuralSegmentation object.
Definition PrintDetector.h:475
NeuralSegmentation()
Construct a new NeuralSegmentation with default config.
Definition PrintDetector.h:483
Null argument is not allowed.
Definition EnrollmentException.h:156
void WriteTo(Writer &writer) const override
Function serializes configuration via provided Writer.
Definition PrintDetector.h:67
void SetNarrowFingerPreference(bool expectNarrow)
Informs the print detector to anticipate narrow fingers.
Definition PrintDetector.h:48
bool GetNarrowFingerPreference() const
Retrieves information about the expected narrowness of detected fingers.
Definition PrintDetector.h:58
PrintDetectorConfig()=default
Default PrintDetector configuration is.
PrintDetector implements segmentation by means of Innovatrics ISegLib library.
Definition PrintDetector.h:93
virtual inno_PrintDetector_result DoDetect(const std::shared_ptr< PrintExecutor > &executor, const std::shared_ptr< Image > &image, FormattingLogger &logger)=0
Template method for various segmentation strategies.
PrintDetector()
Construct a new PrintDetector object GlobalPrintExecutor is used for PrintSegment detection.
Definition PrintDetector.h:141
std::vector< std::shared_ptr< PrintSegment > > Segment(const std::shared_ptr< PrintCapture > &capture) final
Detects segments in given image The Function scans the provided capture to locate fingers.
Definition PrintDetector.h:105
PrintDetector(std::shared_ptr< PrintExecutor > executor)
Construct a new PrintDetector object.
Definition PrintDetector.h:152
It holds rectangle vertexes, width, height.
Definition ImageAttribute.h:357
Provides interface for serialization of all classes.
Definition Writer.h:164
virtual void Write(const char *name, const Serializable &s)=0
Serialize serializable.