bef_effect_ai_face_attribute.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #ifndef _BEF_EFFECT_FACE_ATTRIBUTE_H_
  2. #define _BEF_EFFECT_FACE_ATTRIBUTE_H_
  3. #if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
  4. #if BEF_EFFECT_ANDROID_WITH_JNI
  5. #include<jni.h>
  6. #endif
  7. #endif
  8. #include "bef_effect_ai_public_define.h"
  9. #include "bef_effect_ai_face_detect.h"
  10. typedef enum {
  11. BEF_FACE_ATTRIBUTE_AGE = 0x00000001, //年龄
  12. BEF_FACE_ATTRIBUTE_GENDER = 0x00000002, //性别
  13. BEF_FACE_ATTRIBUTE_EXPRESSION = 0x00000004, //表情
  14. BEF_FACE_ATTRIBUTE_ATTRACTIVE = 0x00000008, //颜值
  15. BEF_FACE_ATTRIBUTE_HAPPINESS = 0x00000010, //开心程度
  16. BEF_FACE_ATTRIBUTE_CONFUSE = 0x00000400, //疑惑
  17. } bef_ai_face_attribute_types;
  18. typedef enum {
  19. BEF_FACE_ATTRIBUTE_ForceDetect = 0x10000000, //未加平滑的裸数据,重置缓存,在切换摄像头时等上下帧剧烈变化时使用
  20. //用于处理切换摄像头,跟踪的人脸ID 混淆的问题
  21. } bef_ai_face_attribut_config;
  22. /*
  23. *@brief 表情类别枚举
  24. **/
  25. typedef enum {
  26. BEF_FACE_ATTRIBUTE_ANGRY = 0, //生气
  27. BEF_FACE_ATTRIBUTE_DISGUST = 1, //厌恶
  28. BEF_FACE_ATTRIBUTE_FEAR = 2, //害怕
  29. BEF_FACE_ATTRIBUTE_HAPPY = 3, //高兴
  30. BEF_FACE_ATTRIBUTE_SAD = 4, //伤心
  31. BEF_FACE_ATTRIBUTE_SURPRISE = 5, //吃惊
  32. BEF_FACE_ATTRIBUTE_NEUTRAL = 6, //平静
  33. BEF_FACE_ATTRIBUTE_NUM_EXPRESSION = 7 //支持的表情个数
  34. }bef_ai_face_attribute_expression_type;
  35. /*
  36. *@brief 模型类别枚举
  37. **/
  38. typedef enum {
  39. BEF_FACE_ATTRIBUTE_MODEL_AGE = 0,
  40. BEF_FACE_ATTRIBUTE_MODEL_EXP = 1,
  41. BEF_FACE_ATTRIBUTE_MODEL_CONFUSED = 2
  42. }bef_ai_face_attribute_model_type;
  43. /*
  44. *@breif 单个人脸属性结构体
  45. **/
  46. typedef struct bef_ai_face_attribute_info {
  47. float age; // 预测的年龄值, 值范围【0,100】之间
  48. float boy_prob; // 预测为男性的概率值,值范围【0.0,1.0】之间
  49. float attractive; // 预测的颜值分数,范围【0,100】之间
  50. float happy_score; // 预测的微笑程度,范围【0,100】之间
  51. bef_ai_face_attribute_expression_type exp_type; // 预测的表情类别
  52. float exp_probs[BEF_FACE_ATTRIBUTE_NUM_EXPRESSION]; // 预测的每个表情的概率,未加平滑处理
  53. // extra
  54. float real_face_prob; // 预测属于真人脸的概率,用于区分雕塑、漫画等非真实人脸
  55. float quality; // 预测人脸的质量分数,范围【0,100】之间
  56. float arousal; // 情绪的强烈程度
  57. float valence; // 情绪的正负情绪程度
  58. float sad_score; // 伤心程度
  59. float angry_score; // 生气程度
  60. float surprise_score; // 吃惊的程度
  61. float mask_prob; // 预测带口罩的概率
  62. float wear_hat_prob; // 戴帽子的概率
  63. float mustache_prob; // 有胡子的概率
  64. float lipstick_prob; // 涂口红的概率
  65. float wear_glass_prob; // 带普通眼镜的概率
  66. float wear_sunglass_prob; // 带墨镜的概率
  67. float blur_score; // 模糊程度
  68. float illumination; // 光照
  69. float confused_prob; ///< 疑惑表情概率
  70. } bef_ai_face_attribute_info;
  71. typedef enum {
  72. // 身份相关的属性(性别、年龄)检测隔帧数,默认值为12;
  73. BEF_FACE_ATTRIBUTE_IDRelatedDetectInterval = 1,
  74. // 非身份相关的属性(表情、颜值、微笑程度)检测隔帧数,默认值为1,即每帧都识别;
  75. // 保留字段,当前不可设;
  76. BEF_FACE_ATTRIBUTE_DetectInterval = 2,
  77. // 当身份相关的属性识别置信度足够高时,停止计算该属性(结果在SDK中存储中正常返回,对外不感知)
  78. // 默认值为1,表示打开,设置为0,表示关闭;
  79. BEF_FACE_ATTRIBUTE_IDRelatedAccumulateResult = 3,
  80. }bef_ai_face_attribute_param_config_type;
  81. /*
  82. *@brief 多个人脸属性结构体
  83. *@param
  84. * face_count 有效的人脸个数
  85. **/
  86. typedef struct bef_ai_face_attribute_result {
  87. bef_ai_face_attribute_info attr_info[BEF_MAX_FACE_NUM]; //存放人脸属性结果数组
  88. int face_count; //有效的人脸个数,即表示attr_info中的前face_count个人脸是有效的
  89. } bef_ai_face_attribute_result;
  90. /**
  91. * @brief 创建人脸属性检测的句柄
  92. * @param [in] config Config of face attribute detect algorithm
  93. * 人脸属性检测算法的配置
  94. * @param [in] strModelPath 模型文件所在路径
  95. * @param [out] handle Created face attribute detect handle
  96. * 创建的人脸属性检测句柄
  97. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_base_define.h
  98. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_base_define.h
  99. */
  100. BEF_SDK_API bef_effect_result_t
  101. bef_effect_ai_face_attribute_create(
  102. unsigned long long config,
  103. const char * strModelPath,
  104. bef_effect_handle_t *handle
  105. );
  106. /**
  107. * @brief 初始化人脸属性模型
  108. * @param [in] handle Created face attribute detect handle
  109. * 已创建的人脸属性检测句柄
  110. * @param [in] strModelPath 模型文件所在路径
  111. * @param [in] type 模型文件类型
  112. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_base_define.h
  113. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_base_define.h
  114. */
  115. BEF_SDK_API bef_effect_result_t
  116. bef_effect_ai_face_attribute_init_model(
  117. bef_effect_handle_t handle,
  118. const char * strModelPath,
  119. bef_ai_face_attribute_model_type type
  120. );
  121. /**
  122. * @brief 单个人脸属性检测
  123. * @param [in] handle Created face attribute detect handle
  124. * 已创建的人脸属性检测句柄
  125. * @param [in] image Image base address
  126. * 输入图片的数据指针
  127. * @param [in] pixel_format Pixel format of input image
  128. * 输入图片的格式
  129. * @param [in] image_width Image width
  130. * 输入图像的宽度 (以像素为单位)
  131. * @param [in] image_height Image height
  132. * 输入图像的高度 (以像素为单位)
  133. * @param [in] image_stride Image stride in each row
  134. * 输入图像每一行的步长 (以像素为单位)
  135. * @param [in] ptr_base_info 人脸检测结果
  136. * @param [in] detect_config Config of face detect, for example
  137. * 人脸检测相关的配置
  138. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_base_define.h
  139. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_base_define.h
  140. */
  141. BEF_SDK_API bef_effect_result_t
  142. bef_effect_ai_face_attribute_detect(
  143. bef_effect_handle_t handle,
  144. const unsigned char *image,
  145. bef_ai_pixel_format pixel_format,
  146. int image_width,
  147. int image_height,
  148. int image_stride,
  149. const bef_ai_face_106 *ptr_base_info,
  150. unsigned long long config,
  151. bef_ai_face_attribute_info *ptr_face_attribute_info
  152. );
  153. /**
  154. * @brief 多个人脸属性检测
  155. * @param [in] handle Created face attribute detect handle
  156. * 已创建的人脸属性检测句柄
  157. * @param [in] image Image base address
  158. * 输入图片的数据指针
  159. * @param [in] pixel_format Pixel format of input image
  160. * 输入图片的格式
  161. * @param [in] image_width Image width
  162. * 输入图像的宽度 (以像素为单位)
  163. * @param [in] image_height Image height
  164. * 输入图像的高度 (以像素为单位)
  165. * @param [in] image_stride Image stride in each row
  166. * 输入图像每一行的步长 (以像素为单位)
  167. * @param [in] ptr_base_info 人脸检测结果
  168. * @param [in] face_count 人脸检测人脸数
  169. * @param [in] detect_config Config of face detect, for example
  170. * 人脸检测相关的配置
  171. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_base_define.h
  172. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_base_define.h
  173. */
  174. BEF_SDK_API bef_effect_result_t
  175. bef_effect_ai_face_attribute_detect_batch(
  176. bef_effect_handle_t handle,
  177. const unsigned char *image,
  178. bef_ai_pixel_format pixel_format,
  179. int image_width,
  180. int image_height,
  181. int image_stride,
  182. const bef_ai_face_106 *ptr_base_info,
  183. int face_count,
  184. unsigned long long config,
  185. bef_ai_face_attribute_result *ptr_face_attribute_result
  186. );
  187. /**
  188. * @brief Set face attribute detect parameter based on type
  189. * 设置人脸属性检测的相关参数
  190. * @param [in] handle Created face detect handle
  191. * 已创建的人脸检测句柄
  192. * @param [in] type Face detect type that needs to be set, check bef_face_detect_type for the detailed
  193. * 需要设置的人体检测类型,可参考 bef_face_detect_type
  194. * @param [in] value Type value, check bef_face_detect_type for the detailed
  195. * 参数值, 具体请参数 bef_face_detect_type 枚举中的说明
  196. * @return If succeed return BEF_RESULT_SUC, other value please refer bef_effect_base_define.h
  197. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_base_define.h
  198. */
  199. BEF_SDK_API bef_effect_result_t
  200. bef_effect_ai_face_attribute_setparam(
  201. bef_effect_handle_t handle,
  202. bef_ai_face_attribute_param_config_type type,
  203. float value
  204. );
  205. /**
  206. * @param [in] handle Destroy the created face attribute detect handle
  207. * 销毁创建的人脸属性检测句柄
  208. */
  209. BEF_SDK_API void
  210. bef_effect_ai_face_attribute_destroy(
  211. bef_effect_handle_t handle
  212. );
  213. /**
  214. * @brief 人脸属性检测授权
  215. * @param [in] handle Created face attribute detect handle
  216. * 已创建的人脸检测句柄
  217. * @param [in] license 授权文件字符串
  218. * @param [in] length 授权文件字符串长度
  219. * @return If succeed return BEF_RESULT_SUC, other value please refer bef_effect_ai_public_define.h
  220. * 成功返回 BEF_RESULT_SUC, 授权码非法返回 BEF_RESULT_INVALID_LICENSE ,其它失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  221. */
  222. #if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
  223. #if BEF_EFFECT_ANDROID_WITH_JNI
  224. BEF_SDK_API bef_effect_result_t bef_effect_ai_face_attribute_check_license(JNIEnv *env, jobject context,
  225. bef_effect_handle_t handle,
  226. const char *licensePath);
  227. #else
  228. BEF_SDK_API bef_effect_result_t bef_effect_ai_face_attribute_check_license(bef_effect_handle_t handle,
  229. const char *licensePath);
  230. #endif
  231. #else
  232. #ifdef __APPLE__
  233. BEF_SDK_API bef_effect_result_t bef_effect_ai_face_attribute_check_license(bef_effect_handle_t handle,
  234. const char *licensePath);
  235. #endif
  236. #endif
  237. BEF_SDK_API bef_effect_result_t
  238. bef_effect_ai_face_attribute_check_online_license(bef_effect_handle_t handle, const char *licensePath);
  239. #endif // _BEF_EFFECT_FACE_DETECT_AI_H_