Enrollment 28.2.0
Loading...
Searching...
No Matches
OFIQFace.h
Go to the documentation of this file.
1
9
10#pragma once
11
21#include <cstdint>
22#include <enrollment/Export.h>
23#include <memory>
24#include <vector>
25
26namespace inno
27{
28 extern "C"
29 {
30 INNO_ENROLLMENT_API void inno_ofiq_get_bounding_box(void* impl,
31 int* topLeftX,
32 int* topLeftY,
33 size_t* width,
34 size_t* height,
35 ErrorCallbacks error);
36 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_sharpness(void* impl, ErrorCallbacks error);
37 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_unified_quality_score(void* impl, ErrorCallbacks error);
38 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_background_uniformity(void* impl, ErrorCallbacks error);
39 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_illumination_uniformity(void* impl, ErrorCallbacks error);
40 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_luminance_mean(void* impl, ErrorCallbacks error);
41 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_luminance_variance(void* impl, ErrorCallbacks error);
42 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_under_exposure_prevention(void* impl, ErrorCallbacks error);
43 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_over_exposure_prevention(void* impl, ErrorCallbacks error);
44 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_dynamic_range(void* impl, ErrorCallbacks error);
45 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_compression_artifacts(void* impl, ErrorCallbacks error);
46 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_natural_colour(void* impl, ErrorCallbacks error);
47 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_single_face_present(void* impl, ErrorCallbacks error);
48 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_eyes_open(void* impl, ErrorCallbacks error);
49 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_mouth_closed(void* impl, ErrorCallbacks error);
50 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_eyes_visible(void* impl, ErrorCallbacks error);
51 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_mouth_occlusion_prevention(void* impl, ErrorCallbacks error);
52 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_face_occlusion_prevention(void* impl, ErrorCallbacks error);
53 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_inter_eye_distance(void* impl, ErrorCallbacks error);
54 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_head_size(void* impl, ErrorCallbacks error);
55 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_leftward_crop_of_the_face_image(void* impl, ErrorCallbacks error);
56 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_rightward_crop_of_the_face_image(void* impl, ErrorCallbacks error);
57 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_margin_above_of_the_face_image(void* impl, ErrorCallbacks error);
58 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_margin_below_of_the_face_image(void* impl, ErrorCallbacks error);
59 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_head_pose_yaw(void* impl, ErrorCallbacks error);
60 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_head_pose_pitch(void* impl, ErrorCallbacks error);
61 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_head_pose_roll(void* impl, ErrorCallbacks error);
62 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_expression_neutrality(void* impl, ErrorCallbacks error);
63 INNO_ENROLLMENT_API uint8_t inno_ofiq_get_no_head_coverings(void* impl, ErrorCallbacks error);
64 }
65
72 */
73 class OFIQFace : public Serializable
74 {
75 public:
88 */
89 static std::shared_ptr<OFIQFace> Create(const std::shared_ptr<FaceCapture>& capture,
90 const std::shared_ptr<FaceExecutor>& executor)
91 {
92 if (capture == nullptr)
93 {
94 throw NullArgumentException("capture cannot be null");
95 }
96 if (executor == nullptr)
97 {
98 throw NullArgumentException("executor cannot be null");
99 }
100
101 auto bgr = capture->image->AsRawBGR();
102 FaceDestroyer deleter = nullptr;
103 void* ptr = executor->CreateOFIQFace(GlobalLogger::Get(),
104 bgr.Data().data(),
105 bgr.width,
106 bgr.height,
107 static_cast<unsigned int>(bgr.dpi),
108 bgr.Data().size(),
109 &deleter,
110 ThrowOnError{});
111
112 auto pimpl = std::unique_ptr<void, FaceDestroyer>(ptr, deleter);
113 return std::shared_ptr<OFIQFace>(new OFIQFace(std::move(pimpl)));
114 }
115
126 */
127 static std::shared_ptr<OFIQFace> Create(const std::shared_ptr<FaceCapture>& capture)
128 {
129 return Create(capture, GlobalFaceExecutor::Get());
130 }
131
135 */
136 void WriteTo(Writer& writer) const final
137 {
138 auto writeOnSuccess = [&writer](const char* name, auto&& func)
139 {
140 try
141 {
142 auto value = func();
143 writer.Write(name, value);
144 }
145 catch (...) // NOLINT(bugprone-empty-catch) - skip writing this field on error
146 {
147 }
148 };
149 writer.Write("bb", GetBoundingBox());
150 writeOnSuccess("sh", [this]() { return GetSharpness(); });
151 writeOnSuccess("uqs", [this]() { return GetUnifiedQualityScore(); });
152 writeOnSuccess("bu", [this]() { return GetBackgroundUniformity(); });
153 writeOnSuccess("iu", [this]() { return GetIlluminationUniformity(); });
154 writeOnSuccess("lmn", [this]() { return GetLuminanceMean(); });
155 writeOnSuccess("lmv", [this]() { return GetLuminanceVariance(); });
156 writeOnSuccess("uep", [this]() { return GetUnderExposurePrevention(); });
157 writeOnSuccess("oep", [this]() { return GetOverExposurePrevention(); });
158 writeOnSuccess("dr", [this]() { return GetDynamicRange(); });
159 writeOnSuccess("ca", [this]() { return GetCompressionArtifacts(); });
160 writeOnSuccess("nc", [this]() { return GetNaturalColour(); });
161 writeOnSuccess("sfp", [this]() { return GetSingleFacePresent(); });
162 writeOnSuccess("eo", [this]() { return GetEyesOpen(); });
163 writeOnSuccess("mc", [this]() { return GetMouthClosed(); });
164 writeOnSuccess("ev", [this]() { return GetEyesVisible(); });
165 writeOnSuccess("mop", [this]() { return GetMouthOcclusionPrevention(); });
166 writeOnSuccess("fop", [this]() { return GetFaceOcclusionPrevention(); });
167 writeOnSuccess("ied", [this]() { return GetInterEyeDistance(); });
168 writeOnSuccess("hs", [this]() { return GetHeadSize(); });
169 writeOnSuccess("lco", [this]() { return GetLeftwardCropOfTheFaceImage(); });
170 writeOnSuccess("rco", [this]() { return GetRightwardCropOfTheFaceImage(); });
171 writeOnSuccess("mao", [this]() { return GetMarginAboveOfTheFaceImage(); });
172 writeOnSuccess("mbo", [this]() { return GetMarginBelowOfTheFaceImage(); });
173 writeOnSuccess("hpy", [this]() { return GetHeadPoseYaw(); });
174 writeOnSuccess("hpp", [this]() { return GetHeadPosePitch(); });
175 writeOnSuccess("hpr", [this]() { return GetHeadPoseRoll(); });
176 writeOnSuccess("en", [this]() { return GetExpressionNeutrality(); });
177 writeOnSuccess("nhc", [this]() { return GetNoHeadCoverings(); });
178 }
179
183 */
184 [[nodiscard]] Rectangle GetBoundingBox() const
185 {
186 int topLeftX = 0;
187 int topLeftY = 0;
188 size_t width = 0UL;
189 size_t height = 0UL;
190 inno_ofiq_get_bounding_box(impl.get(), &topLeftX, &topLeftY, &width, &height, ThrowOnError{});
191 return { { topLeftX, topLeftY },
192 { static_cast<X>(topLeftX + width), topLeftY },
193 { static_cast<X>(topLeftX + width), static_cast<Y>(topLeftY + height) },
194 { topLeftX, static_cast<Y>(topLeftY + height) } };
195 }
207 */
208 [[nodiscard]] uint8_t GetSharpness() const
209 {
210 return inno_ofiq_get_sharpness(impl.get(), ThrowOnError{});
211 }
218 */
219 [[nodiscard]] uint8_t GetUnifiedQualityScore() const
220 {
221 return inno_ofiq_get_unified_quality_score(impl.get(), ThrowOnError{});
222 }
228 */
229 [[nodiscard]] uint8_t GetBackgroundUniformity() const
230 {
231 return inno_ofiq_get_background_uniformity(impl.get(), ThrowOnError{});
232 }
239 */
240 [[nodiscard]] uint8_t GetIlluminationUniformity() const
241 {
242 return inno_ofiq_get_illumination_uniformity(impl.get(), ThrowOnError{});
243 }
249 */
250 [[nodiscard]] uint8_t GetLuminanceMean() const
251 {
252 return inno_ofiq_get_luminance_mean(impl.get(), ThrowOnError{});
253 }
259 */
260 [[nodiscard]] uint8_t GetLuminanceVariance() const
261 {
262 return inno_ofiq_get_luminance_variance(impl.get(), ThrowOnError{});
263 }
269 */
270 [[nodiscard]] uint8_t GetUnderExposurePrevention() const
271 {
272 return inno_ofiq_get_under_exposure_prevention(impl.get(), ThrowOnError{});
273 }
279 */
280 [[nodiscard]] uint8_t GetOverExposurePrevention() const
281 {
282 return inno_ofiq_get_over_exposure_prevention(impl.get(), ThrowOnError{});
283 }
289 */
290 [[nodiscard]] uint8_t GetDynamicRange() const
291 {
292 return inno_ofiq_get_dynamic_range(impl.get(), ThrowOnError{});
293 }
299 */
300 [[nodiscard]] uint8_t GetCompressionArtifacts() const
301 {
302 return inno_ofiq_get_compression_artifacts(impl.get(), ThrowOnError{});
303 }
310 */
311 [[nodiscard]] uint8_t GetNaturalColour() const
312 {
313 return inno_ofiq_get_natural_colour(impl.get(), ThrowOnError{});
314 }
320 */
321 [[nodiscard]] uint8_t GetSingleFacePresent() const
322 {
323 return inno_ofiq_get_single_face_present(impl.get(), ThrowOnError{});
324 }
330 */
331 [[nodiscard]] uint8_t GetEyesOpen() const
332 {
333 return inno_ofiq_get_eyes_open(impl.get(), ThrowOnError{});
334 }
340 */
341 [[nodiscard]] uint8_t GetMouthClosed() const
342 {
343 return inno_ofiq_get_mouth_closed(impl.get(), ThrowOnError{});
344 }
350 */
351 [[nodiscard]] uint8_t GetEyesVisible() const
352 {
353 return inno_ofiq_get_eyes_visible(impl.get(), ThrowOnError{});
354 }
360 */
361 [[nodiscard]] uint8_t GetMouthOcclusionPrevention() const
362 {
363 return inno_ofiq_get_mouth_occlusion_prevention(impl.get(), ThrowOnError{});
364 }
370 */
371 [[nodiscard]] uint8_t GetFaceOcclusionPrevention() const
372 {
373 return inno_ofiq_get_face_occlusion_prevention(impl.get(), ThrowOnError{});
374 }
381 */
382 [[nodiscard]] uint8_t GetInterEyeDistance() const
383 {
384 return inno_ofiq_get_inter_eye_distance(impl.get(), ThrowOnError{});
385 }
391 */
392 [[nodiscard]] uint8_t GetHeadSize() const
393 {
394 return inno_ofiq_get_head_size(impl.get(), ThrowOnError{});
395 }
401 */
402 [[nodiscard]] uint8_t GetLeftwardCropOfTheFaceImage() const
403 {
404 return inno_ofiq_get_leftward_crop_of_the_face_image(impl.get(), ThrowOnError{});
405 }
411 */
412 [[nodiscard]] uint8_t GetRightwardCropOfTheFaceImage() const
413 {
414 return inno_ofiq_get_rightward_crop_of_the_face_image(impl.get(), ThrowOnError{});
415 }
421 */
422 [[nodiscard]] uint8_t GetMarginAboveOfTheFaceImage() const
423 {
424 return inno_ofiq_get_margin_above_of_the_face_image(impl.get(), ThrowOnError{});
425 }
431 */
432 [[nodiscard]] uint8_t GetMarginBelowOfTheFaceImage() const
433 {
434 return inno_ofiq_get_margin_below_of_the_face_image(impl.get(), ThrowOnError{});
435 }
441 */
442 [[nodiscard]] uint8_t GetHeadPoseYaw() const
443 {
444 return inno_ofiq_get_head_pose_yaw(impl.get(), ThrowOnError{});
445 }
451 */
452 [[nodiscard]] uint8_t GetHeadPosePitch() const
453 {
454 return inno_ofiq_get_head_pose_pitch(impl.get(), ThrowOnError{});
455 }
461 */
462 [[nodiscard]] uint8_t GetHeadPoseRoll() const
463 {
464 return inno_ofiq_get_head_pose_roll(impl.get(), ThrowOnError{});
465 }
471 */
472 [[nodiscard]] uint8_t GetExpressionNeutrality() const
473 {
474 return inno_ofiq_get_expression_neutrality(impl.get(), ThrowOnError{});
475 }
481 */
482 [[nodiscard]] uint8_t GetNoHeadCoverings() const
483 {
484 return inno_ofiq_get_no_head_coverings(impl.get(), ThrowOnError{});
485 }
486
487 OFIQFace() = delete;
488 virtual ~OFIQFace() = default;
489 OFIQFace(const OFIQFace&) = delete;
490 OFIQFace(OFIQFace&&) = delete;
491 OFIQFace& operator=(const OFIQFace&) = delete;
492 OFIQFace& operator=(OFIQFace&&) = delete;
493
494 private:
495 explicit OFIQFace(std::unique_ptr<void, FaceDestroyer> pimpl)
496 : impl(std::move(pimpl))
497 {
498 }
499
500 std::unique_ptr<void, FaceDestroyer> impl;
501 };
502} // namespace inno
static std::shared_ptr< FaceExecutor > Get()
Provides current executor.
Definition FaceExecutor.h:1361
static std::shared_ptr< Logger > Get()
Provides current logger.
Definition Logger.h:281
Null argument is not allowed.
Definition EnrollmentException.h:156
It provides quality measures as defined in ISO/IEC 29794-5:2025.
Definition OFIQFace.h:73
uint8_t GetOverExposurePrevention() const
Over-exposure prevention.
Definition OFIQFace.h:279
uint8_t GetLeftwardCropOfTheFaceImage() const
Leftward crop of the face image.
Definition OFIQFace.h:401
uint8_t GetNaturalColour() const
Natural colour of the face image.
Definition OFIQFace.h:310
void WriteTo(Writer &writer) const final
Serialize OFIQFace to Writer.
Definition OFIQFace.h:135
uint8_t GetMarginAboveOfTheFaceImage() const
Margin above the face image.
Definition OFIQFace.h:421
uint8_t GetHeadPoseRoll() const
Head pose roll (tilt about the nose axis).
Definition OFIQFace.h:461
uint8_t GetIlluminationUniformity() const
Illumination uniformity across the face.
Definition OFIQFace.h:239
uint8_t GetRightwardCropOfTheFaceImage() const
Rightward crop of the face image.
Definition OFIQFace.h:411
uint8_t GetMarginBelowOfTheFaceImage() const
Margin below the face image.
Definition OFIQFace.h:431
uint8_t GetNoHeadCoverings() const
No head coverings.
Definition OFIQFace.h:481
uint8_t GetCompressionArtifacts() const
Absence of compression artefacts.
Definition OFIQFace.h:299
Rectangle GetBoundingBox() const
Provides bounding box of detected face.
Definition OFIQFace.h:183
uint8_t GetInterEyeDistance() const
Inter-eye distance quality.
Definition OFIQFace.h:381
uint8_t GetEyesVisible() const
Eyes visible.
Definition OFIQFace.h:350
uint8_t GetLuminanceMean() const
Luminance mean of the face image.
Definition OFIQFace.h:249
uint8_t GetUnderExposurePrevention() const
Under-exposure prevention.
Definition OFIQFace.h:269
static std::shared_ptr< OFIQFace > Create(const std::shared_ptr< FaceCapture > &capture)
Create OFIQ from FaceCapture using default executor set in GlobalFaceExecutor.
Definition OFIQFace.h:126
uint8_t GetEyesOpen() const
Eyes open.
Definition OFIQFace.h:330
uint8_t GetMouthClosed() const
Mouth closed.
Definition OFIQFace.h:340
uint8_t GetSingleFacePresent() const
Single face present in the image.
Definition OFIQFace.h:320
uint8_t GetLuminanceVariance() const
Luminance variance in the face image.
Definition OFIQFace.h:259
uint8_t GetHeadSize() const
Head size in the image.
Definition OFIQFace.h:391
uint8_t GetBackgroundUniformity() const
Background uniformity of the face image.
Definition OFIQFace.h:228
uint8_t GetDynamicRange() const
Dynamic range of the face image.
Definition OFIQFace.h:289
static std::shared_ptr< OFIQFace > Create(const std::shared_ptr< FaceCapture > &capture, const std::shared_ptr< FaceExecutor > &executor)
Create OFIQ from FaceCapture using the given executor.
Definition OFIQFace.h:88
uint8_t GetHeadPosePitch() const
Head pose pitch (up-down tilt).
Definition OFIQFace.h:451
uint8_t GetHeadPoseYaw() const
Head pose yaw (left-right rotation).
Definition OFIQFace.h:441
uint8_t GetUnifiedQualityScore() const
Unified quality score (QS) mapping native OFIQ quality.
Definition OFIQFace.h:218
uint8_t GetFaceOcclusionPrevention() const
Face occlusion prevention.
Definition OFIQFace.h:370
uint8_t GetMouthOcclusionPrevention() const
Mouth occlusion prevention.
Definition OFIQFace.h:360
uint8_t GetExpressionNeutrality() const
Expression neutrality.
Definition OFIQFace.h:471
uint8_t GetSharpness() const
Provides sharpness of the face.
Definition OFIQFace.h:207
It holds rectangle vertexes, width, height.
Definition ImageAttribute.h:357
Provides interface for serialization of all classes.
Definition Writer.h:164
int Y
Y coordinate.
Definition ImageAttribute.h:117
int X
X coordinate.
Definition ImageAttribute.h:112