| Face Engine SDK 5.32.0 A face detection, recognition and tracking engine.

IAttributeEstimator.h
1 #pragma once
2
3 #include <fsdk/IObject.h>
4 #include <fsdk/FSDKError.h>
5 #include <fsdk/Optional.h>
6 #include <fsdk/Types.h>
7
8 #include <algorithm>
9
10 namespace fsdk {
11
12 #ifndef DOXYGEN_SHOULD_SKIP_THIS
13 DECLARE_SMARTPTR(IAttributeEstimator);
14
24 struct EthnicityEstimation {
25 float africanAmerican;
26 float indian;
27 float asian;
28 float caucasian;
29
30 enum Ethnicities {
31 AfricanAmerican = 0,
32 Indian,
33 Asian,
34 Caucasian,
35 Count
36 };
37
42 inline Ethnicities getPredominantEthnicity() const;
43
49 inline float getEthnicityScore(Ethnicities ethnicity) const;
50 };
51
64 struct IAttributeEstimator : IRefCounted {
69 enum EstimationRequest {
70 estimateAge = 1 << 0,
71 estimateGender = 1 << 1,
72 estimateEthnicity = 1 << 2,
73 estimateAll = 0xffff
74 };
75
79 struct EstimationResult {
81 Optional<float> age;
83 Optional<float> gender;
85 Optional<float> genderScore;
87 Optional<EthnicityEstimation> ethnicity;
88 };
89
100 virtual Result<FSDKError>
101 estimate(const Image& warp, const EstimationRequest request, EstimationResult& out) const noexcept = 0;
102
115 virtual ResultValue<FSDKError, EstimationResult> estimate(
116 Span<const Image> warps,
117 const EstimationRequest request,
118 Span<EstimationResult> results) const noexcept = 0;
119
132 virtual Result<FSDKError> validate(
133 Span<const Image> warps,
134 const EstimationRequest request,
135 Span<Result<FSDKError>> errors) const noexcept = 0;
136 };
137
141 using EstimationRequest = IAttributeEstimator::EstimationRequest;
142 using AttributeEstimationResult = IAttributeEstimator::EstimationResult;
143
144 /*
145 Implementation details.
146 */
147 EthnicityEstimation::Ethnicities EthnicityEstimation::getPredominantEthnicity() const {
148 const float* arr = &this->africanAmerican;
149 return static_cast<EthnicityEstimation::Ethnicities>(
150 std::distance(arr, std::max_element(arr, arr + EthnicityEstimation::Count)));
151 }
152
153 /*
154 Implementation details.
155 */
156 float EthnicityEstimation::getEthnicityScore(EthnicityEstimation::Ethnicities ethnicity) const {
157 return *(&this->africanAmerican + static_cast<uint32_t>(ethnicity));
158 }
159
160 /*
161 Implementation details.
162 */
163 inline IAttributeEstimator::EstimationRequest
164 operator|(IAttributeEstimator::EstimationRequest first, IAttributeEstimator::EstimationRequest second) {
165 return static_cast<IAttributeEstimator::EstimationRequest>(
166 static_cast<int>(first) | static_cast<int>(second));
167 }
168
170 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
171 } // namespace fsdk
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:56
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
Types.h
Common data types and structures.
IObject.h
Object system types and interfaces.
FSDKError.h
Common SDK error codes.
fsdk::FaceOcclusionType::Count
Total number of occlusion types.