3DiVi Face SDK  3.24.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
EmotionsEstimator.h
Go to the documentation of this file.
1 
13 #ifndef __PBIO_API__PBIO__EMOTIONS_ESTIMATOR_H_
14 #define __PBIO_API__PBIO__EMOTIONS_ESTIMATOR_H_
15 
16 #include <sstream>
17 #include <vector>
18 
19 
20 #include "ComplexObject.h"
21 #include "RawSample.h"
22 #include "SmartPtr.h"
23 #include "Error.h"
24 #include "stl_wraps_impls/WrapOStreamImpl.h"
25 
26 
27 namespace pbio
28 {
29 
30 class FacerecService;
31 
41 class EmotionsEstimator : public ComplexObject
42 {
43 public:
44 
50  typedef LightSmartPtr<EmotionsEstimator>::tPtr Ptr;
51 
57  enum Emotion
58  {
65 
72 
79 
86 
93 
100 
107  };
108 
115  {
122 
128  float confidence;
129  };
130 
142  typedef std::vector<EmotionConfidence> EstimatedEmotionsVector;
143 
170 
171 private:
172 
174  const DHPtr &dll_handle,
175  void* impl);
176 
177  friend class FacerecService;
178  friend class object_with_ref_counter<EmotionsEstimator>;
179 };
180 
181 } // pbio namespace
182 
183 
184 
188 
189 namespace pbio
190 {
191 
192 
193 inline
194 EmotionsEstimator::EmotionsEstimator(
195  const DHPtr &dll_handle,
196  void* impl):
197 ComplexObject(dll_handle, impl)
198 {
199  // nothing else
200 }
201 
202 
203 inline
204 std::vector<EmotionsEstimator::EmotionConfidence> EmotionsEstimator::estimateEmotions(
205  const pbio::RawSample &sample) const
206 {
207  void* exception = NULL;
208 
209  std::ostringstream data_oss;
210 
211  stl_wraps::WrapOStreamImpl data_oss_w(data_oss);
212 
213  const int count = _dll_handle->EmotionsEstimator_estimateEmotions(
214  _impl,
215  (pbio::facerec::RawSampleImpl const*) sample._impl,
216  &data_oss_w,
217  pbio::stl_wraps::WrapOStreamImpl::write_func,
218  &exception);
219 
220  checkException(exception, *_dll_handle);
221 
222  std::istringstream data_iss(data_oss.str());
223 
224  std::vector<EmotionConfidence> result(count);
225 
226  for(int i = 0; i < count; ++i)
227  {
228  int32_t emotion;
229  float confidence;
230 
231  data_iss.read((char*)&emotion, sizeof(emotion));
232  data_iss.read((char*)&confidence, sizeof(confidence));
233 
234  result[i].emotion = (Emotion) emotion;
235  result[i].confidence = confidence;
236  }
237 
238  return result;
239 }
240 
241 
242 
243 } // pbio namespace
244 
245 #endif // __PBIO_API__PBIO__EMOTIONS_ESTIMATOR_H_
Surprised.
Definition: EmotionsEstimator.h:85
Interface object for creating other interface objects.
Definition: FacerecService.h:64
Interface object that stores a captured face sample.
Definition: RawSample.h:49
LightSmartPtr< EmotionsEstimator >::tPtr Ptr
Alias for the type of a smart pointer to EmotionsEstimator.
Definition: EmotionsEstimator.h:50
Neutral.
Definition: EmotionsEstimator.h:64
std::vector< EmotionConfidence > EstimatedEmotionsVector
Vector of estimated emotions with confidence coefficients. In descending confidence order...
Definition: EmotionsEstimator.h:142
Sad.
Definition: EmotionsEstimator.h:106
Error - the class of exceptions thrown when errors occur.
Emotion with confidence.
Definition: EmotionsEstimator.h:114
float confidence
Positive real number in the range of [0; 1].
Definition: EmotionsEstimator.h:128
Emotion emotion
Emotion.
Definition: EmotionsEstimator.h:121
Happy.
Definition: EmotionsEstimator.h:71
Emotion
Emotions.
Definition: EmotionsEstimator.h:57
Scared.
Definition: EmotionsEstimator.h:99
SmartPtr.
EstimatedEmotionsVector estimateEmotions(const pbio::RawSample &sample) const
Estimates the emotion of a given face sample.
Definition: EmotionsEstimator.h:204
Definition: FacerecService.mm:79
Angry.
Definition: EmotionsEstimator.h:78
Disgusted.
Definition: EmotionsEstimator.h:92
Interface object for estimation of emotions.
Definition: EmotionsEstimator.h:41