Enrollment 28.2.0
Loading...
Searching...
No Matches
PrintSegment.h
Go to the documentation of this file.
1
9
10#pragma once
11
19#include <memory>
20#include <mutex>
21#include <optional>
22
23// cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes: This is not a
24// problem because we are using them only as read only.
25// cppcoreguidelines-avoid-const-or-ref-data-members: We design te API with const member variables instead of
26// implementing getter methods. This is nicely transformed in C# to properties. Usually our objects are immutable by
27// intention to have no problem in multithreaded applications.
28// NOLINTBEGIN(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes,cppcoreguidelines-avoid-const-or-ref-data-members)
29namespace inno
30{
34 */
36 {
37 public:
45 */
46 void SetImageDimensions(ImageWidth width, ImageHeight height)
47 {
48 if (width == 0)
49 {
50 throw EnrollmentInvalidArgumentException("Width can not be 0");
51 }
52 if (height == 0)
53 {
54 throw EnrollmentInvalidArgumentException("Height can not be 0");
55 }
56
57 w = width;
58 h = height;
59 }
63 */
64 [[nodiscard]] ImageWidth GetImageWidth() const
65 {
66 return w;
67 }
71 */
72 [[nodiscard]] ImageHeight GetImageHeight() const
73 {
74 return h;
75 }
76
77 [[nodiscard]] ImageDimensions GetImageDimensions() const
78 {
79 return { w, h };
80 }
81
85 */
86 void SetBackgroundColor(RGBA color)
87 {
88 backgroundColor = std::move(color);
89 }
93 */
94 [[nodiscard]] RGBA GetBackgroundColor() const
95 {
96 return backgroundColor;
97 }
98
106 */
107 void EnableAlignedCropping(bool aligned)
108 {
109 alignedCrop = aligned;
110 }
111
116 */
117 [[nodiscard]] bool IsAlignedCroppingEnabled() const
118 {
119 return alignedCrop;
120 }
121
130 PrintCropConfiguration() = default;
131 virtual ~PrintCropConfiguration() = default;
134 PrintCropConfiguration& operator=(const PrintCropConfiguration&) = delete;
135 PrintCropConfiguration& operator=(PrintCropConfiguration&&) = delete;
136
137 private:
138 ImageWidth w = 0;
139 ImageHeight h = 0;
140 RGBA backgroundColor = Colors::White;
141 bool alignedCrop = true;
142 };
143
144 // Internal interface to overcome cyclic includes between this header and PrintCapture.
145 class CropablePrint : public Serializable
146 {
147 public:
155 [[nodiscard]] virtual std::shared_ptr<Image> CropPrint(const Rectangle& rectangle,
156 const PrintCropConfiguration& cropCfg) const = 0;
157
158 CropablePrint() = default;
159 virtual ~CropablePrint() = default;
160 CropablePrint(const CropablePrint&) = delete;
161 CropablePrint(CropablePrint&&) = delete;
162 CropablePrint& operator=(const CropablePrint&) = delete;
163 CropablePrint& operator=(CropablePrint&&) = delete;
164 };
165
172 */
173 class PrintSegment final : public Serializable
174 {
175 public:
178 // Provides angle of prints 0-360 in degrees.
179 const int angle;
180
186 */
187 bool HasPosition() const
188 {
189 const std::scoped_lock lock(posMutex);
190 return pos.has_value();
191 }
192
197 */
198 void SetPosition(const PrintPosition& position)
199 {
200 const std::scoped_lock lock(posMutex);
201 pos = position;
202 }
208 */
210 {
211 const std::scoped_lock lock(posMutex);
212
213 if (!pos.has_value())
214 {
215 throw EnrollmentRuntimeException("No print position");
216 }
217
218 return pos.value();
219 }
220
227 */
228 std::shared_ptr<PrintSegment> Resize(Rectangle::Width newWidth, Rectangle::Height newHeight) const
229 {
230 auto newRect = roundingBox.Resize(newWidth, newHeight);
231 return std::make_shared<PrintSegment>(imagePrint, attr, newRect, angle, ConvertPosition(), exec);
232 }
233
242 */
243 std::shared_ptr<Print> ToPrint()
244 {
245 static const PrintCropConfiguration DefaultCropCfg;
246 return ToPrint(DefaultCropCfg);
247 }
248
258 */
259 std::shared_ptr<Print> ToPrint(const PrintCropConfiguration& cfg)
260 {
261 const std::scoped_lock lock(posMutex);
262
263 if (not pos.has_value())
264 {
265 throw EnrollmentRuntimeException("Not possible to create print from PrintSegment without position");
266 }
267
268 return Print::Create(imagePrint->CropPrint(roundingBox, cfg), pos.value(), attr, exec);
269 }
270
274 */
275 void WriteTo(Writer& writer) const final
276 {
277 writer.Write("rb", roundingBox);
278 writer.Write("a", angle);
279 writer.Write("t", attr);
280
281 const std::scoped_lock lock(posMutex);
282
283 if (pos.has_value())
284 {
285 writer.Write("p", static_cast<unsigned int>(pos.value()));
286 }
287 }
288
289 PrintSegment() = delete;
290 virtual ~PrintSegment() = default;
291 PrintSegment(const PrintSegment& s)
292 : roundingBox(s.roundingBox)
293 , angle(s.angle)
294 , imagePrint(s.imagePrint)
295 , exec(s.exec)
296 , pos(s.pos)
297 , attr(s.attr)
298 {
299 }
300 PrintSegment(PrintSegment&&) = delete;
301 PrintSegment(std::shared_ptr<CropablePrint> pc,
302 PrintAttributes pa,
303 Rectangle r,
304 int a,
305 int position,
306 std::shared_ptr<PrintExecutor> executor)
307 : roundingBox(std::move(r))
308 , angle(a)
309 , imagePrint(std::move(pc))
310 , exec(std::move(executor))
311 , attr(std::move(pa))
312 {
313 // When segmentation algorithm deduce position then assign it
314 if (position > 0)
315 {
316 pos = static_cast<PrintPosition>(position);
317 }
318 }
319 PrintSegment& operator=(const PrintSegment&) = delete;
320 PrintSegment& operator=(PrintSegment&&) = delete;
321
322 private:
323 std::shared_ptr<CropablePrint> imagePrint;
324 std::shared_ptr<PrintExecutor> exec;
325 std::optional<PrintPosition> pos;
326 mutable std::mutex posMutex;
327 PrintAttributes attr;
328
329 int ConvertPosition() const
330 {
331 const std::scoped_lock lock(posMutex);
332 if (pos.has_value())
333 {
334 return static_cast<int>(pos.value());
335 }
336
337 return 0;
338 }
339 };
340} // namespace inno
341// NOLINTEND(cppcoreguidelines-non-private-member-variables-in-classes,misc-non-private-member-variables-in-classes,cppcoreguidelines-avoid-const-or-ref-data-members)
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
It holds width and height of Image.
Definition ImageAttribute.h:281
Holds print cropping configuration.
Definition PrintSegment.h:35
ImageHeight GetImageHeight() const
It gets output image height.
Definition PrintSegment.h:71
RGBA GetBackgroundColor() const
It provides background color for rounding box area that is out of image.
Definition PrintSegment.h:93
bool IsAlignedCroppingEnabled() const
Get Aligned Crop Configuration.
Definition PrintSegment.h:116
PrintCropConfiguration()=default
Create default PrintCropConfiguration object.
ImageWidth GetImageWidth() const
It gets output image width.
Definition PrintSegment.h:63
void SetImageDimensions(ImageWidth width, ImageHeight height)
Function sets output image dimension.
Definition PrintSegment.h:45
void SetBackgroundColor(RGBA color)
It sets background color rounding box area that is out of image.
Definition PrintSegment.h:85
void EnableAlignedCropping(bool aligned)
Enable Aligned Cropping.
Definition PrintSegment.h:106
Segment detected in print capture Usually the segment has also position that is assigned by segmentat...
Definition PrintSegment.h:173
void WriteTo(Writer &writer) const final
Function serializes slap segment.
Definition PrintSegment.h:274
const Rectangle roundingBox
Found rounding box of segmented fingertip.
Definition PrintSegment.h:176
void SetPosition(const PrintPosition &position)
Set the Position.
Definition PrintSegment.h:197
PrintPosition GetPosition()
Returns print position.
Definition PrintSegment.h:208
std::shared_ptr< Print > ToPrint(const PrintCropConfiguration &cfg)
It transforms segment to Print.
Definition PrintSegment.h:258
std::shared_ptr< PrintSegment > Resize(Rectangle::Width newWidth, Rectangle::Height newHeight) const
Create new segment with given width and height.
Definition PrintSegment.h:227
bool HasPosition() const
It checks if position is set.
Definition PrintSegment.h:186
std::shared_ptr< Print > ToPrint()
It transforms segment to Print.
Definition PrintSegment.h:242
static std::shared_ptr< Print > Create(std::shared_ptr< Image > img, const PrintPosition &position, const PrintAttributes &pa=PrintAttributes(), std::shared_ptr< PrintExecutor > executor=GlobalPrintExecutor::Get())
Constructor creates Print object.
Definition Print.h:625
It holds RGB color with transparency.
Definition ImageAttribute.h:908
It holds rectangle vertexes, width, height.
Definition ImageAttribute.h:357
Dimension Height
Rectangle height.
Definition ImageAttribute.h:367
Dimension Width
Rectangle width.
Definition ImageAttribute.h:371
Interface that MUST be implemented by all classes those want to be serialized.
Definition Writer.h:27
Provides interface for serialization of all classes.
Definition Writer.h:164
ImageDimension ImageHeight
Image Height.
Definition ImageAttribute.h:36
ImageDimension ImageWidth
Image Width.
Definition ImageAttribute.h:41
PrintPosition
It is position of finger on hands.
Definition PrintPosition.h:29