| Face Engine SDK 5.12.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
19 struct EthnicityEstimation {
20 float africanAmerican;
21 float indian;
22 float asian;
23 float caucasian;
24
25 enum Ethnicities {
26 AfricanAmerican = 0,
27 Indian,
28 Asian,
29 Caucasian,
30 Count
31 };
32
37 inline Ethnicities getPredominantEthnicity() const;
38
44 inline float getEthnicityScore(Ethnicities ethnicity) const;
45 };
46
59 struct IAttributeEstimator : IRefCounted {
64 enum EstimationRequest {
65 estimateAge = 1 << 0,
66 estimateGender = 1 << 1,
67 estimateEthnicity = 1 << 2,
68 estimateAll = 0xffff
69 };
70
74 struct EstimationResult {
76 Optional<float> age;
78 Optional<float> gender;
80 Optional<float> genderScore;
82 Optional<EthnicityEstimation> ethnicity;
83 };
84
95 virtual Result<FSDKError> estimate(
96 const Image& warp,
97 const EstimationRequest request,
98 EstimationResult& out) const noexcept = 0;
99
112 virtual ResultValue<FSDKError, EstimationResult> estimate(
113 Span<const Image> warps,
114 const EstimationRequest request,
115 Span<EstimationResult> results) const noexcept = 0;
116
129 virtual Result<FSDKError>
130 validate(
131 Span<const Image> warps,
132 const EstimationRequest request,
133 Span<Result<FSDKError>> errors) const noexcept = 0;
134 };
135
139 using EstimationRequest = IAttributeEstimator::EstimationRequest;
140 using AttributeEstimationResult = IAttributeEstimator::EstimationResult;
141
142 /*
143 Implementation details.
144 */
145 EthnicityEstimation::Ethnicities
146 EthnicityEstimation::getPredominantEthnicity() const {
147 const float* arr = &this->africanAmerican;
148 return static_cast<EthnicityEstimation::Ethnicities>(
149 std::distance(arr, std::max_element(arr, arr+EthnicityEstimation::Count))
150 );
151 }
152
153 /*
154 Implementation details.
155 */
156 float
157 EthnicityEstimation::getEthnicityScore(
158 EthnicityEstimation::Ethnicities ethnicity
159 ) const {
160 return *(&this->africanAmerican + static_cast<uint32_t>(ethnicity));
161 }
162
163 /*
164 Implementation details.
165 */
166 inline IAttributeEstimator::EstimationRequest
167 operator|(
168 IAttributeEstimator::EstimationRequest first,
169 IAttributeEstimator::EstimationRequest second
170 ) {
171 return static_cast<IAttributeEstimator::EstimationRequest>(
172 static_cast<int>(first) | static_cast<int>(second)
173 );
174 }
175
176 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
177
178 } // namespace sdk
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:59
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.