bef_effect_ai_pet_face.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef ANDROIDDEMO_BEF_EFFECT_AI_PET_FACE_H
  2. #define ANDROIDDEMO_BEF_EFFECT_AI_PET_FACE_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. #define AI_PET_MAX_POINT_NUM 90 // 宠物脸的关键点的最大点数
  10. #define AI_CAT_POINT_NUM 82 // 猫:82点
  11. #define AI_DOG_POINT_NUM 76 // 狗:76点(不加耳朵)
  12. #define AI_OTHER_POINT_NUM 4 // 其它动物:4点(目前不支持)
  13. #define AI_MAX_PET_NUM 10
  14. #define AI_PET_OPEN_LEFT_EYE 0x00000001 // 左眼睛是否睁开
  15. #define AI_PET_OPEN_RIGHT_EYE 0x00000002 // 右眼睛是否睁开
  16. #define AI_PET_OPEN_MOUTH 0x00000004 // 嘴巴是否张开
  17. typedef void *PetFaceHandle; ///< 关键点检测句柄
  18. typedef enum {
  19. BEF_CAT = 1, // 猫
  20. BEF_DOG = 2, // 狗
  21. BEF_HUMAN = 3, // 人(目前不支持)
  22. BEF_OTHERS = 99, // 其它宠物类型(目前不支持)
  23. }bef_ai_pet_face_type;
  24. typedef enum {
  25. BEF_DetCat = 0x00000001, // 开启猫脸检测
  26. BEF_DetDog = 0x00000002, // 开启狗脸检测
  27. BEF_QuickMode = 0x00000004, // 开启快速版本
  28. }bef_ai_pet_face_config_type;
  29. typedef struct bef_ai_pet_info_st {
  30. bef_ai_pet_face_type type; /// < 宠物类型
  31. bef_ai_rect rect; /// < 代表面部的矩形区域
  32. float score; /// < 宠物脸检测的置信度
  33. bef_ai_fpoint points_array[AI_PET_MAX_POINT_NUM]; /// < 宠物脸关键点的数组
  34. float yaw; /// < 水平转角,真实度量的左负右正
  35. float pitch; /// < 俯仰角,真实度量的上负下正
  36. float roll; /// < 旋转角,真实度量的左负右正
  37. int id; /// < faceID: 每个检测到的宠物脸拥有唯一id,跟踪丢失以后重新被检测到,会有一个新的id
  38. unsigned int action; /// < 脸部动作,目前只包括:左眼睛睁闭,右眼睛睁闭,嘴巴睁闭,
  39. /// < action 的第1,2,3位分别编码: 左眼睛睁闭,右眼睛睁闭,嘴巴睁闭,其余位数预留
  40. int ear_type; ///< 判断是竖耳还是垂耳,竖耳为0,垂耳为1
  41. } bef_ai_pet_face_info, *p_bef_ai_pet_face_info;
  42. /// @brief 检测结果
  43. typedef struct bef_ai_pet_face_result_st {
  44. bef_ai_pet_face_info p_faces[AI_MAX_PET_NUM]; ///< 检测到的宠物脸信息
  45. int face_count; ///< 检测到的宠物脸数目,p_faces 数组中,只有face_count个结果是有效的;
  46. } bef_ai_pet_face_result, *p_bef_ai_pet_face_result;
  47. /**
  48. * @brief 创建宠物脸检测的句柄
  49. *
  50. * @param [in] strModelPath 模型文件所在路径
  51. *
  52. * @param [in] config Config of pet face detect algorithm 宠物脸检测算法的配置
  53. * 可以配置只检测猫,只检测狗,或者同时检测猫狗
  54. * 例如:只检测狗 detect_config = bef_ai_pet_face_config_type::BEF_DetDog
  55. * 同时检测猫狗: 只检测狗 detect_config = bef_ai_pet_face_config_type::BEF_DetDog|bef_ai_pet_face_config_type::BEF_DetCat
  56. *
  57. * @param: max_face_num:指定最多能够检测到的宠物脸数目;
  58. *
  59. * @param [out] handle Created face detect handle
  60. * 创建的宠物脸检测句柄
  61. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_ai_public_define.h
  62. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  63. */
  64. BEF_SDK_API
  65. bef_effect_result_t
  66. bef_effect_ai_pet_face_create(
  67. const char * strModelPath,
  68. long long config,
  69. unsigned int maxNum,
  70. bef_effect_handle_t *handle
  71. );
  72. /**
  73. * @brief 宠物脸检测
  74. * @param [in] handle Created face detect handle
  75. * 已创建的宠物脸检测句柄
  76. * @param [in] image Image base address
  77. * 输入图片的数据指针
  78. * @param [in] pixel_format Pixel format of input image
  79. * 输入图片的格式
  80. * @param [in] image_width Image width
  81. * 输入图像的宽度 (以像素为单位)
  82. * @param [in] image_height Image height
  83. * 输入图像的高度 (以像素为单位)
  84. * @param [in] image_stride Image stride in each row
  85. * 输入图像每一行的步长 (以像素为单位)
  86. * @param [in] orientation Image orientation
  87. * 输入图像的转向,具体请参考 bef_effect_ai_public_define.h 中的 bef_rotate_type
  88. * @param [out] p_pet_face_result 存放结果信息,需外部分配好内存,需保证空间大于等于设置的最大检测宠物脸数
  89. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_ai_public_define.h
  90. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  91. */
  92. BEF_SDK_API
  93. bef_effect_result_t bef_effect_ai_pet_face_detect(
  94. bef_effect_handle_t handle,
  95. const unsigned char *image,
  96. bef_ai_pixel_format pixel_format,
  97. int image_width,
  98. int image_height,
  99. int image_stride,
  100. bef_ai_rotate_type orientation,
  101. bef_ai_pet_face_result *p_pet_face_result
  102. );
  103. /**
  104. * @param [in] handle Destroy the created pet face detect handle
  105. * 销毁创建的宠物脸检测句柄
  106. */
  107. BEF_SDK_API
  108. bef_effect_result_t bef_effect_ai_pet_face_release(bef_effect_handle_t handle);
  109. /**
  110. * @brief 宠物脸授权
  111. * @param [in] handle Created pet face handle
  112. * 已创建的宠物脸检测句柄
  113. * @param [in] license 授权文件字符串
  114. * @param [in] length 授权文件字符串长度
  115. * @return If succeed return BEF_RESULT_SUC, other value please refer bef_effect_ai_public_define.h
  116. * 成功返回 BEF_RESULT_SUC, 授权码非法返回 BEF_RESULT_INVALID_LICENSE ,其它失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  117. */
  118. #if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
  119. #if BEF_EFFECT_ANDROID_WITH_JNI
  120. BEF_SDK_API bef_effect_result_t bef_effect_ai_pet_face_check_license(JNIEnv *env, jobject context,
  121. bef_effect_handle_t handle,
  122. const char *licensePath);
  123. #else
  124. BEF_SDK_API bef_effect_result_t bef_effect_ai_pet_face_check_license(bef_effect_handle_t handle,
  125. const char *licensePath);
  126. #endif
  127. #else
  128. #ifdef __APPLE__
  129. BEF_SDK_API bef_effect_result_t bef_effect_ai_pet_face_check_license(bef_effect_handle_t handle, const char *licensePath);
  130. #endif
  131. #endif
  132. BEF_SDK_API bef_effect_result_t
  133. bef_effect_ai_pet_face_check_online_license(bef_effect_handle_t handle, const char *licensePath);
  134. #endif //ANDROIDDEMO_BEF_EFFECT_AI_PET_FACE_H