3DiVi Face SDK  3.21.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
FaceAttributesEstimator.h
Go to the documentation of this file.
1 
9 #ifndef __PBIO_API__PBIO__FACE_ATTRIBUTES_ESTIMATOR_H_
10 #define __PBIO_API__PBIO__FACE_ATTRIBUTES_ESTIMATOR_H_
11 
12 
13 #include "ComplexObject.h"
14 #include "RawSample.h"
15 #include "SmartPtr.h"
16 
17 
18 namespace pbio
19 {
20 
21 class FacerecService;
22 
28 class FaceAttributesEstimator : public ComplexObject
29 {
30 public:
31 
37  typedef LightSmartPtr<FaceAttributesEstimator>::tPtr Ptr;
38 
39 
45  struct EyeStateScore{
46 
52  enum EyeState{
53  NOT_COMPUTED = 0,
54  CLOSED = 1,
55  OPENED = 2
56  } eye_state;
57 
63  float score;
64 
65  EyeStateScore() : eye_state( NOT_COMPUTED ), score( -1.f ) {}
66  };
67 
68 
74  struct Attribute
75  {
81  bool verdict;
82 
88  float score;
89 
96  NOT_COMPUTED = 0,
97  NO_MASK = 1,
98  HAS_MASK = 2
99  } mask_attribute;
100 
106  Attribute() : verdict( false ), score( -1.0f ), mask_attribute( NOT_COMPUTED ) {}
107 
108  EyeStateScore left_eye_state, right_eye_state;
109  };
110 
132  Attribute estimate(const pbio::RawSample &sample) const;
133 
134 private:
135 
137  const DHPtr &dll_handle,
138  void* impl);
139 
140  friend class FacerecService;
141  friend class object_with_ref_counter<FaceAttributesEstimator>;
142 };
143 
144 } // pbio namespace
145 
146 
147 
151 
152 namespace pbio
153 {
154 
155 
156 inline
157 FaceAttributesEstimator::FaceAttributesEstimator(
158  const DHPtr &dll_handle,
159  void* impl):
160 ComplexObject(dll_handle, impl)
161 {
162  // nothing else
163 }
164 
165 
166 inline
168 {
169  Attribute result;
170 
171  std::ostringstream name_task;
172  pbio::stl_wraps::WrapOStreamImpl name_task_wrap(name_task);
173 
174  void* exception = NULL;
175 
176  _dll_handle->FaceAttributesEstimator_getTaskName(
177  _impl,
178  &name_task_wrap,
179  pbio::stl_wraps::WrapOStream::write_func,
180  &exception);
181 
182  checkException(exception, *_dll_handle);
183 
184  if (name_task.str() == "masked_face" || name_task.str() == "masked_face_v2")
185  {
186  int32_t verdict;
187 
188  void* exception = NULL;
189 
190  _dll_handle->FaceAttributesEstimator_estimateMaskedFace(
191  _impl,
192  (pbio::facerec::RawSampleImpl const*) sample._impl,
193  &verdict,
194  &result.score,
195  &exception);
196 
197  checkException(exception, *_dll_handle);
198 
199  result.verdict = verdict;
200 
201  result.mask_attribute = verdict ? Attribute::MaskAttribute::HAS_MASK: Attribute::MaskAttribute::NO_MASK;
202  }else
203  if (name_task.str() == "eyes_openness" || name_task.str() == "eyes_openness_v2" )
204  {
205  EyeStateScore left_eye_state, right_eye_state;
206  int32_t left_eye_verdict, right_eye_verdict;
207 
208  void* exception = NULL;
209 
210  _dll_handle->FaceAttributesEstimator_estimateEyesOpenness(
211  _impl,
212  (pbio::facerec::RawSampleImpl const*) sample._impl,
213  &left_eye_verdict,
214  &right_eye_verdict,
215  &result.left_eye_state.score,
216  &result.right_eye_state.score,
217  &exception);
218 
219  checkException(exception, *_dll_handle);
220 
221  if (result.left_eye_state.score == -1.f)
222  result.left_eye_state.eye_state = EyeStateScore::NOT_COMPUTED;
223  else
224  result.left_eye_state.eye_state = left_eye_verdict ? EyeStateScore::OPENED: EyeStateScore::CLOSED;
225 
226  if (result.right_eye_state.score == -1.f)
227  result.right_eye_state.eye_state = EyeStateScore::NOT_COMPUTED;
228  else
229  result.right_eye_state.eye_state = right_eye_verdict ? EyeStateScore::OPENED: EyeStateScore::CLOSED;
230  }else
231  PBI0x3dfb4fe3Assert(0xec9eb983, false, "FaceAttributesEstimator: unknown name_task: '" + name_task.str() + "'");
232 
233 
234  return result;
235 }
236 
237 
238 } // pbio namespace
239 
240 #endif // __PBIO_API__PBIO__FACE_ATTRIBUTES_ESTIMATOR_H_
float score
Probability of a required attribute.
Definition: FaceAttributesEstimator.h:88
Interface object for creating other interface objects.
Definition: FacerecService.h:64
Interface object used to estimate attributes of the face.
Definition: FaceAttributesEstimator.h:28
Interface object that stores a captured face sample.
Definition: RawSample.h:49
Attribute()
Estimated left or right eye state and probability of eye opening.
Definition: FaceAttributesEstimator.h:106
MaskAttribute
Detailed description for attribute - medical mask .
Definition: FaceAttributesEstimator.h:95
Attribute estimate(const pbio::RawSample &sample) const
Estimates if there is is a required attribute on a given face sample.
Definition: FaceAttributesEstimator.h:167
The result of determining the presence of the required attribute on the face.
Definition: FaceAttributesEstimator.h:74
RawSample - Interface object that stores a captured face sample.
float score
Probability of eye opening.
Definition: FaceAttributesEstimator.h:63
Estimated eye state and probability of eye opening.
Definition: FaceAttributesEstimator.h:45
SmartPtr.
LightSmartPtr< FaceAttributesEstimator >::tPtr Ptr
Alias for the type of a smart pointer to FaceAttributesEstimator.
Definition: FaceAttributesEstimator.h:37
EyeState
Estimated eye state.
Definition: FaceAttributesEstimator.h:52
bool verdict
Verdict.
Definition: FaceAttributesEstimator.h:81