Enrollment 28.2.0
Loading...
Searching...
No Matches
FaceCropConfiguration.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "enrollment/Export.h"
16
17namespace inno
18{
22 */
23 class FaceCropConfiguration : public Serializable
24 {
25 public:
36 */
37 void SetCropBackground(const RGBA& background)
38 {
39 if (IsBackgroundTransparent(background) && cropMethod != FaceCrop::FULL_NOT_ALIGNED)
40 {
42 "Not possible to set transparent background for already set crop method " + ToString(cropMethod));
43 }
44
45 cropBackground = background;
46 }
47
52 */
53 [[nodiscard]] RGBA GetCropBackground() const
54 {
55 return cropBackground;
56 }
57
69 */
70 void SetCropMethod(FaceCrop method)
71 {
72 if (!IsFaceCropMethodValid(method))
73 {
74 throw EnrollmentInvalidArgumentException("Unknown crop method provided");
75 }
76 if (IsScale() && method == FaceCrop::TOKEN_NOT_FRONTAL)
77 {
78 throw EnrollmentInvalidArgumentException("Not possible to set " +
80 " crop method when scale is not 1.0");
81 }
82 if (IsBackgroundTransparent() && method != FaceCrop::FULL_NOT_ALIGNED)
83 {
84 throw EnrollmentInvalidArgumentException("Not possible to set crop method " + ToString(method) +
85 " when background is transparent");
86 }
87
88 cropMethod = method;
89 }
90
95 */
96 [[nodiscard]] FaceCrop GetCropMethod() const
97 {
98 return cropMethod;
99 }
100
110 */
111 void SetCropScale(float scale)
112 {
113 static constexpr float MinScale = 0.3F;
114 static constexpr float MaxScale = 2.0F;
115 if (scale < MinScale || scale > MaxScale)
116 {
117 throw EnrollmentInvalidArgumentException("Crop scale MUST be in range <0.3, 2.0>");
118 }
119 if (cropMethod == FaceCrop::TOKEN_NOT_FRONTAL)
120 {
121 throw EnrollmentInvalidArgumentException("Not possible to set crop scale for " +
122 ToString(FaceCrop::TOKEN_NOT_FRONTAL) + " crop method");
123 }
124 cropScale = scale;
125 }
126
131 */
132 [[nodiscard]] float GetCropScale() const
133 {
134 return cropScale;
135 }
136
140 */
141 void WriteTo(Writer& writer) const final
142 {
143 writer.Write("c", cropBackground);
144 writer.Write("m", static_cast<unsigned int>(cropMethod));
145 writer.Write("s", cropScale);
146 }
147
154 FaceCropConfiguration() = default;
157 FaceCropConfiguration& operator=(const FaceCropConfiguration&) = default;
158 FaceCropConfiguration& operator=(FaceCropConfiguration&&) = default;
159 virtual ~FaceCropConfiguration() = default;
160
161 private:
162 RGBA cropBackground = Colors::White;
163 FaceCrop cropMethod = FaceCrop::TOKEN;
164 float cropScale = 1.0F;
165
166 [[nodiscard]] bool IsScale() const
167 {
168 static constexpr int Scale100 = 100;
169 return static_cast<int>(cropScale * Scale100) != Scale100;
170 }
171 static bool IsBackgroundTransparent(const RGBA& background)
172 {
173 return background.transparency != RGBA::FULLY_OPAQUE;
174 }
175 [[nodiscard]] bool IsBackgroundTransparent() const
176 {
177 return cropBackground.transparency != RGBA::FULLY_OPAQUE;
178 }
179 };
180} // namespace inno
Base exception for all enrollment-sdk invalid argument exceptions.
Definition EnrollmentException.h:96
void WriteTo(Writer &writer) const final
Function serializes configuration via provided Writer.
Definition FaceCropConfiguration.h:140
void SetCropBackground(const RGBA &background)
Set the Crop Background color Background with transparency is only allowed when method is FaceCrop::F...
Definition FaceCropConfiguration.h:36
void SetCropMethod(FaceCrop method)
Set the Crop method.
Definition FaceCropConfiguration.h:69
FaceCrop GetCropMethod() const
Get the Crop method.
Definition FaceCropConfiguration.h:95
RGBA GetCropBackground() const
Get the Crop Background object.
Definition FaceCropConfiguration.h:52
void SetCropScale(float scale)
Set the Crop scale.
Definition FaceCropConfiguration.h:110
FaceCropConfiguration()=default
Default configuration is.
float GetCropScale() const
Get the Crop scale.
Definition FaceCropConfiguration.h:131
It holds RGB color with transparency.
Definition ImageAttribute.h:908
@ FULLY_OPAQUE
Color is fully opaque, means it is visible.
Definition ImageAttribute.h:920
unsigned char transparency
Transparency where 0 is fully transparent and 255 is fully opaque.
Definition ImageAttribute.h:913
Provides interface for serialization of all classes.
Definition Writer.h:164
static constexpr bool IsFaceCropMethodValid(FaceCrop faceCrop)
Function validates the value of FaceCrop enum.
Definition FaceCrop.h:53
FaceCrop
Defines different Crop methods.
Definition FaceCrop.h:23
@ FULL_NOT_ALIGNED
Crops bounding box provided by FaceCrop::FULL method as is from original FaceCapture.
Definition FaceCrop.h:41
@ TOKEN
Token Frontal Image cropping method defined in ISO/IEC 19794-5 standard.
Definition FaceCrop.h:38
@ TOKEN_NOT_FRONTAL
Image cropping method similar to TOKEN but works quite well even on non-frontal images It will produc...
Definition FaceCrop.h:26