bef_effect_ai_face_verify.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef _BEF_EFFECT_FACE_VREIFY_AI_H_
  2. #define _BEF_EFFECT_FACE_VREIFY_AI_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. #define BEF_AI_MAX_FACE_VERIFY_NUM 10
  11. #define BEF_AI_FACE_FEATURE_DIM 128 // 人脸特征的维数
  12. // 结果信息
  13. typedef struct bef_ai_face_verify_info_s{
  14. bef_ai_face_106 base_infos[BEF_AI_MAX_FACE_VERIFY_NUM];// 基本的人脸信息,包含106点、动作、姿态
  15. float features[BEF_AI_MAX_FACE_VERIFY_NUM][BEF_AI_FACE_FEATURE_DIM]; // 存放人脸特征
  16. int valid_face_num; // 检测到的人脸数目
  17. } bef_ai_face_verify_info;
  18. /**
  19. * 创建人脸比对的句柄
  20. *@brief 初始化handle
  21. *@param face_verify_param_path 人脸识别模型的文件路径
  22. *@param max_face_num 要处理的最大人脸数,该值不能大于AI_MAX_FACE_NUM
  23. *@param [out] handle Created face verify handle
  24. * 创建的人手检测句柄
  25. *@return If succeed return BEF_RESULT_SUC, other value please see bef_effect_ai_public_define.h
  26. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  27. */
  28. BEF_SDK_API bef_effect_result_t
  29. bef_effect_ai_face_verify_create(
  30. const char *face_verify_param_path,
  31. const int max_face_num,
  32. bef_effect_handle_t *handle
  33. );
  34. /**
  35. * @brief 人脸特征提取,支持最多10个人脸
  36. * @param [in] handle Created face verify handle
  37. * 已创建的人脸检测句柄
  38. * @param [in] image Image base address
  39. * 输入图片的数据指针
  40. * @param [in] pixel_format Pixel format of input image
  41. * 输入图片的格式 支持RGBA, BGRA, BGR, RGB, GRAY(YUV暂时不支持)
  42. * @param [in] image_width Image width
  43. * 输入图像的宽度 (以像素为单位)
  44. * @param [in] image_height Image height
  45. * 输入图像的高度 (以像素为单位)
  46. * @param [in] image_stride Image stride in each row
  47. * 输入图像每一行的步长 (以像素为单位)
  48. * @param [in] orientation Image orientation
  49. * 输入图像的转向,具体请参考 bef_effect_ai_public_define.h 中的 bef_rotate_type
  50. * @param [in] face_input bef_ai_face_info
  51. * 人脸106点检测结果
  52. * @param [out] face_info_ptr 存放结果信息,需外部分配好内存,需保证空间大于等于设置的最大检测人脸数
  53. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_ai_public_define.h
  54. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  55. */
  56. BEF_SDK_API bef_effect_result_t
  57. bef_effect_ai_face_extract_feature(
  58. bef_effect_handle_t handle,
  59. const unsigned char *image,
  60. bef_ai_pixel_format pixel_format,
  61. int image_width,
  62. int image_height,
  63. int image_stride,
  64. bef_ai_rotate_type orientation,
  65. const bef_ai_face_info *face_input,
  66. bef_ai_face_verify_info *verify_info_ptr
  67. );
  68. /**
  69. * @brief 单个人脸特征提取
  70. * @param [in] handle Created face verify handle
  71. * 已创建的人脸检测句柄
  72. * @param [in] image Image base address
  73. * 输入图片的数据指针
  74. * @param [in] pixel_format Pixel format of input image
  75. * 输入图片的格式 支持RGBA, BGRA, BGR, RGB, GRAY(YUV暂时不支持)
  76. * @param [in] image_width Image width
  77. * 输入图像的宽度 (以像素为单位)
  78. * @param [in] image_height Image height
  79. * 输入图像的高度 (以像素为单位)
  80. * @param [in] image_stride Image stride in each row
  81. * 输入图像每一行的步长 (以像素为单位)
  82. * @param [in] orientation Image orientation
  83. * 输入图像的转向,具体请参考 bef_effect_ai_public_define.h 中的 bef_rotate_type
  84. * @param [in] face_input bef_ai_face_106
  85. * 单个人脸106点检测结果
  86. * @param [out] face_info_ptr 存放特征信息,需外部分配好内存,需保证空间大于等于定义的特征维度
  87. * @return If succeed return BEF_RESULT_SUC, other value please see bef_effect_ai_public_define.h
  88. * 成功返回 BEF_RESULT_SUC, 失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  89. */
  90. BEF_SDK_API bef_effect_result_t
  91. bef_effect_ai_face_extract_feature_single(
  92. bef_effect_handle_t handle,
  93. const unsigned char *image,
  94. bef_ai_pixel_format pixel_format,
  95. int image_width,
  96. int image_height,
  97. int image_stride,
  98. bef_ai_rotate_type orientation,
  99. const bef_ai_face_106 *face_input,
  100. float *verify_info_ptr
  101. );
  102. /**
  103. * @brief 人脸特征比对
  104. * @param [in] feature1 特征1
  105. *
  106. * @param [in] feature2 特征2
  107. *
  108. * @param [in] size 特征维度
  109. *
  110. * @return [out] 特征距离
  111. **/
  112. BEF_SDK_API double bef_effect_ai_face_verify(const float *feature1,
  113. const float *feature2, int size);
  114. /**
  115. * @brief 特征相似度计算
  116. *
  117. * @param [in] d 特征距离
  118. *
  119. * @return [out] 特征相似度
  120. **/
  121. BEF_SDK_API double bef_effect_ai__dist2score(double d);
  122. /**
  123. * @param [in] handle Destroy the created face detect handle
  124. * 销毁创建的人脸比对句柄
  125. */
  126. BEF_SDK_API void
  127. bef_effect_ai_face_verify_destroy(
  128. bef_effect_handle_t handle
  129. );
  130. /**
  131. * @brief 人脸比对授权
  132. * @param [in] handle Created face detect handle
  133. * 已创建的人脸检测句柄
  134. * @param [in] license 授权文件字符串
  135. * @param [in] length 授权文件字符串长度
  136. * @return If succeed return BEF_RESULT_SUC, other value please refer bef_effect_ai_public_define.h
  137. * 成功返回 BEF_RESULT_SUC, 授权码非法返回 BEF_RESULT_INVALID_LICENSE ,其它失败返回相应错误码, 具体请参考 bef_effect_ai_public_define.h
  138. */
  139. #if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
  140. #if BEF_EFFECT_ANDROID_WITH_JNI
  141. BEF_SDK_API bef_effect_result_t bef_effect_ai_face_verify_check_license(JNIEnv *env, jobject context,
  142. bef_effect_handle_t handle,
  143. const char *licensePath);
  144. #else
  145. BEF_SDK_API bef_effect_result_t bef_effect_ai_face_verify_check_license(bef_effect_handle_t handle,
  146. const char *licensePath);
  147. #endif
  148. #else
  149. #ifdef __APPLE__
  150. BEF_SDK_API bef_effect_result_t bef_effect_ai_face_verify_check_license(bef_effect_handle_t handle, const char *licensePath);
  151. #endif
  152. #endif
  153. BEF_SDK_API bef_effect_result_t
  154. bef_effect_ai_face_verify_check_online_license(bef_effect_handle_t handle, const char *licensePath);
  155. #endif // _BEF_EFFECT_FACE_DETECT_AI_H_