12#include "enrollment/Export.h"
41 class PrintCaptureSegmentation
49 virtual std::vector<std::shared_ptr<PrintSegment>> Segment(
const std::shared_ptr<PrintCapture>& capture) = 0;
51 PrintCaptureSegmentation() =
default;
52 virtual ~PrintCaptureSegmentation() =
default;
53 PrintCaptureSegmentation(
const PrintCaptureSegmentation&) =
delete;
54 PrintCaptureSegmentation(PrintCaptureSegmentation&&) =
delete;
55 PrintCaptureSegmentation& operator=(
const PrintCaptureSegmentation&) =
delete;
56 PrintCaptureSegmentation& operator=(PrintCaptureSegmentation&&) =
delete;
65 :
public CropablePrint
66 ,
public std::enable_shared_from_this<PrintCapture>
70 const std::shared_ptr<Image>
image;
82 static std::shared_ptr<PrintCapture>
Create(
83 std::shared_ptr<Image> img,
87 return std::shared_ptr<PrintCapture>(
new PrintCapture(std::move(img), pa, std::move(executor)));
129 virtual std::vector<std::shared_ptr<PrintSegment>>
SegmentWith(PrintCaptureSegmentation& detector)
131 auto capture = shared_from_this();
132 auto segments = detector.Segment(capture);
133 DoModifySegments(segments);
147 if (cfg.IsAlignedCroppingEnabled())
149 return image->CropAlignedRectangle(rectangle, cfg.GetBackgroundColor(), cfg.GetImageDimensions());
152 return image->CropRectangle(rectangle, cfg.GetBackgroundColor(), cfg.GetImageDimensions());
164 return CropPrint(rectangle, DefaultCropCfg);
173 std::shared_ptr<Image>
Draw(
const std::vector<std::shared_ptr<PrintSegment>>& segments,
176 const RoundingBoxesShape rbs(segments, attr);
177 return image->DrawShape(rbs);
186 writer.Write(
"i",
image);
188 const std::scoped_lock lock(intensityMux);
189 if (intensity.has_value())
191 writer.Write(
"in", intensity.value());
201 const std::scoped_lock lock(intensityMux);
202 if (!intensity.has_value())
206 return intensity.value();
220 : image(std::move(i))
221 , printAttributes(std::move(pa))
222 , exec(std::move(executor))
224 if (image ==
nullptr)
229 virtual void DoWriteTo(Writer& )
const
233 virtual void DoModifySegments(std::vector<std::shared_ptr<PrintSegment>>& segments)
235 ClearPositionInSegments(segments);
238 void ClearPositionInSegments(std::vector<std::shared_ptr<PrintSegment>>& segments)
240 for (
auto& s : segments)
242 if (s->HasPosition())
244 s = std::make_shared<PrintSegment>(
245 shared_from_this(), printAttributes, s->roundingBox, s->angle, 0, exec);
251 class RoundingBoxesShape final :
public ImageShape
254 void DrawIn(ImageShapeDrawer& drawer)
const final
256 for (
const auto& s : segments)
258 auto rs = RectangleShape(s->roundingBox, attr);
263 RoundingBoxesShape(
const std::vector<std::shared_ptr<PrintSegment>>& s, ImageShapeAttributes a)
268 RoundingBoxesShape() =
delete;
269 virtual ~RoundingBoxesShape() =
default;
270 RoundingBoxesShape(
const RoundingBoxesShape&) =
delete;
271 RoundingBoxesShape(RoundingBoxesShape&&) =
delete;
272 RoundingBoxesShape& operator=(
const RoundingBoxesShape&) =
delete;
273 RoundingBoxesShape& operator=(RoundingBoxesShape&&) =
delete;
276 const std::vector<std::shared_ptr<PrintSegment>>& segments;
277 ImageShapeAttributes attr;
280 std::shared_ptr<PrintExecutor> exec;
281 mutable std::mutex printMutex;
282 mutable std::mutex intensityMux;
283 std::vector<std::shared_ptr<Print>> prints;
284 std::optional<uint8_t> intensity;
292 class GuessedHandPosition
301 return hand.has_value();
311 if (!hand.has_value())
324 virtual ~GuessedHandPosition() =
default;
325 GuessedHandPosition(
const GuessedHandPosition&) =
default;
326 GuessedHandPosition(GuessedHandPosition&&) =
default;
327 GuessedHandPosition& operator=(
const GuessedHandPosition&) =
default;
328 GuessedHandPosition& operator=(GuessedHandPosition&&) =
default;
331 std::optional<HandPosition> hand;
339 class SlapCapture final :
public PrintCapture
353 std::vector<std::shared_ptr<PrintSegment>>
SegmentWith(PrintCaptureSegmentation& detector)
final
367 static std::shared_ptr<SlapCapture>
Create(std::shared_ptr<Image> img,
372 return std::shared_ptr<SlapCapture>(
new SlapCapture(std::move(img),
hand, pa, std::move(executor)));
375 static GuessedHandPosition GuessHandPosition(
const std::vector<std::shared_ptr<PrintSegment>>& segments)
380 for (
const auto& i : segments)
382 if (i->HasPosition())
384 auto position = i->GetPosition();
398 if (rightHand == 0 && leftHand > 0)
402 if (rightHand > 0 && leftHand == 0)
406 return GuessedHandPosition{};
415 static int CalculateGlobalAngle(
const std::vector<std::shared_ptr<inno::PrintSegment>>& segments)
417 if (segments.empty())
420 "Not possible to calculate global angle, no segments are given");
423 double sumSines = 0.0;
424 double sumCosines = 0.0;
425 constexpr int StraightAngle = 180;
426 constexpr int CompleteAngle = 360;
430 constexpr double MathPI = 3.14159265358979323846;
432 for (
const auto& segment : segments)
435 const double radians = segment->angle * MathPI / StraightAngle;
438 sumSines += sin(radians);
439 sumCosines += cos(radians);
443 const double averageRadians = atan2(sumSines, sumCosines);
446 double averageDegrees = averageRadians * StraightAngle / MathPI;
448 if (averageDegrees < 0)
450 averageDegrees = CompleteAngle + averageDegrees;
453 return static_cast<int>(averageDegrees);
473 void DoWriteTo(Writer& writer)
const final
475 writer.Write(
"h",
static_cast<unsigned int>(hand));
478 void DoModifySegments(std::vector<std::shared_ptr<PrintSegment>>& ) final
489 class ThumbsCapture final :
public PrintCapture
500 std::vector<std::shared_ptr<PrintSegment>>
SegmentWith(PrintCaptureSegmentation& detector)
final
513 static std::shared_ptr<ThumbsCapture>
Create(
514 std::shared_ptr<Image> img,
518 return std::shared_ptr<ThumbsCapture>(
new ThumbsCapture(std::move(img), pa, std::move(executor)));
536 void DoWriteTo(Writer& )
const final
541 void DoModifySegments(std::vector<std::shared_ptr<PrintSegment>>& segments)
final
543 if (segments.size() == 2)
550 ClearPositionInSegments(segments);
HandPosition
Hand to which slap belongs.
Definition HandPosition.h:17
@ RIGHT
Right hand position.
Definition HandPosition.h:21
@ LEFT
Left hand position.
Definition HandPosition.h:19
Base exception for all enrollment-sdk invalid argument exceptions.
Definition EnrollmentException.h:96
Base exception for all enrollment-sdk runtime exceptions.
Definition EnrollmentException.h:84
static std::shared_ptr< PrintExecutor > Get()
Provides current executor.
Definition PrintExecutor.h:1306
It represents guessed hand position of Slap.
Definition PrintCapture.h:292
bool IsGuessSuccessful() const
Definition PrintCapture.h:298
HandPosition GetHandPosition() const
Definition PrintCapture.h:307
Image DPI.
Definition ImageAttribute.h:47
It holds shape attributes such as color and line width.
Definition ImageShape.h:22
Image resampler for DPI-change operations, including upsampling and downsampling using bicubic interp...
Definition Image.h:584
Image resampler for DPI-change operations, including upsampling and downsampling.
Definition Image.h:530
Interface for library logging.
Definition Logger.h:45
Null argument is not allowed.
Definition EnrollmentException.h:156
Print attributes Holds the print attributes.
Definition PrintAttributes.h:34
It holds all functions and data related to print manipulation.
Definition PrintCapture.h:66
std::shared_ptr< PrintCapture > ChangeDpiTo(ImageDpi targetDpi) const
Create new PrintCapture with given DPI.
Definition PrintCapture.h:98
std::shared_ptr< Image > CropPrint(const Rectangle &rectangle, const PrintCropConfiguration &cfg) const final
It crops image with given rectangle and background color.
Definition PrintCapture.h:143
void WriteTo(Writer &writer) const final
Function serializes print via provided Writer.
Definition PrintCapture.h:183
virtual std::vector< std::shared_ptr< PrintSegment > > SegmentWith(PrintCaptureSegmentation &detector)
It segments print capture.
Definition PrintCapture.h:128
std::shared_ptr< Image > CropPrint(const Rectangle &rectangle) const
It crops image with given rectangle by default PrintCropConfiguration.
Definition PrintCapture.h:160
static std::shared_ptr< PrintCapture > Create(std::shared_ptr< Image > img, const PrintAttributes &pa=PrintAttributes(), std::shared_ptr< PrintExecutor > executor=GlobalPrintExecutor::Get())
Constructor of PrintCapture.
Definition PrintCapture.h:81
std::shared_ptr< Image > Draw(const std::vector< std::shared_ptr< PrintSegment > > &segments, const ImageShapeAttributes &attr) const
It draws rounding boxes into PrintCapture.
Definition PrintCapture.h:172
uint8_t CalculateIntensity()
Function calculates the image intensity.
Definition PrintCapture.h:198
const std::shared_ptr< Image > image
Provides PrintCapture Image.
Definition PrintCapture.h:69
const PrintAttributes printAttributes
Provides PrintCapture Image.
Definition PrintCapture.h:71
std::shared_ptr< PrintCapture > ChangeDpiTo(const Image::ImageResampler &resampler) const
Create new PrintCapture using provided DPI-change configuration.
Definition PrintCapture.h:114
Holds print cropping configuration.
Definition PrintSegment.h:35
uint8_t CalculateIntensity()
Function calculates the image intensity.
Definition Print.h:494
It holds rectangle vertexes, width, height.
Definition ImageAttribute.h:357
It represents PrintCapture with Slap.
Definition PrintCapture.h:339
static std::shared_ptr< SlapCapture > Create(std::shared_ptr< Image > img, const HandPosition &hand, const PrintAttributes &pa=PrintAttributes(), std::shared_ptr< PrintExecutor > executor=GlobalPrintExecutor::Get())
Constructor of SlapCapture.
Definition PrintCapture.h:366
const HandPosition hand
Provides given hand position.
Definition PrintCapture.h:342
static int CalculateGlobalAngle(const std::vector< std::shared_ptr< inno::PrintSegment > > &segments)
Calculates the global angle of segmented prints.
Definition PrintCapture.h:414
std::vector< std::shared_ptr< PrintSegment > > SegmentWith(PrintCaptureSegmentation &detector) final
It segments slap capture.
Definition PrintCapture.h:352
It represents PrintCapture with ThumbsCapture.
Definition PrintCapture.h:489
std::vector< std::shared_ptr< PrintSegment > > SegmentWith(PrintCaptureSegmentation &detector) final
It segments thumbs capture.
Definition PrintCapture.h:499
static std::shared_ptr< ThumbsCapture > Create(std::shared_ptr< Image > img, const PrintAttributes &pa=PrintAttributes(), std::shared_ptr< PrintExecutor > executor=GlobalPrintExecutor::Get())
Constructor sets image and attributes of ThumbsCapture.
Definition PrintCapture.h:512
Provides interface for serialization of all classes.
Definition Writer.h:164
@ LEFT_LITTLE
Little finger on left hand.
Definition PrintPosition.h:69
@ LEFT_THUMB
Thumb on left hand.
Definition PrintPosition.h:53
@ RIGHT_LITTLE
Little on right hand.
Definition PrintPosition.h:49
@ RIGHT_THUMB
Thumb on right hand.
Definition PrintPosition.h:33