FaceSDKManager.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. //
  2. // FaceSDKManager.h
  3. // IDLFaceSDK
  4. //
  5. // Created by Tong,Shasha on 2017/5/15.
  6. // Copyright © 2017年 Baidu. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import <UIKit/UIKit.h>
  10. typedef NS_ENUM(NSInteger, FaceLivenessActionType) {
  11. FaceLivenessActionTypeLiveEye = 0,
  12. FaceLivenessActionTypeLiveMouth = 1,
  13. FaceLivenessActionTypeLiveYawRight = 2,
  14. FaceLivenessActionTypeLiveYawLeft = 3,
  15. FaceLivenessActionTypeLivePitchUp = 4,
  16. FaceLivenessActionTypeLivePitchDown = 5,
  17. FaceLivenessActionTypeLiveYaw = 6,
  18. FaceLivenessActionTypeNoAction = 7,
  19. };
  20. typedef NS_ENUM(NSUInteger, ResultCode) {
  21. ResultCodeOK,
  22. ResultCodePitchOutofDownRange, //头部偏低
  23. ResultCodePitchOutofUpRange, //头部偏高
  24. ResultCodeYawOutofLeftRange, //头部偏左
  25. ResultCodeYawOutofRightRange, //头部偏右
  26. ResultCodePoorIllumination, //光照不足
  27. ResultCodeNoFaceDetected, //没有检测到人脸
  28. ResultCodeDataNotReady,
  29. ResultCodeDataHitOne, //采集到一张照片
  30. ResultCodeDataHitLast, //采集到最后一张照片
  31. ResultCodeImageBlured, //图像模糊
  32. ResultCodeOcclusionLeftEye, //左眼有遮挡
  33. ResultCodeOcclusionRightEye, //右眼有遮挡
  34. ResultCodeOcclusionNose, //鼻子有遮挡
  35. ResultCodeOcclusionMouth, //嘴巴有遮挡
  36. ResultCodeOcclusionLeftContour, //左脸颊有遮挡
  37. ResultCodeOcclusionRightContour, //右脸颊有遮挡
  38. ResultCodeOcclusionChinCoutour, //下颚有遮挡
  39. ResultCodeVerifyInitError, //鉴权失败
  40. ResultCodeVerifyDecryptError,
  41. ResultCodeVerifyInfoFormatError,
  42. ResultCodeVerifyExpired,
  43. ResultCodeVerifyMissRequiredInfo,
  44. ResultCodeVerifyInfoCheckError,
  45. ResultCodeVerifyLocalFileError,
  46. ResultCodeVerifyRemoteDataError,
  47. ResultCodeUnknowType //未知类型
  48. };
  49. typedef NS_ENUM(NSUInteger, TrackResultCode) {
  50. TrackResultCodeOK,
  51. TrackResultCodeImageBlured, // 图像模糊
  52. TrackResultCodePoorIllumination, // 光照不行
  53. TrackResultCodeNoFaceDetected, //没有检测到人脸
  54. TrackResultCodeOcclusionLeftEye, //左眼有遮挡
  55. TrackResultCodeOcclusionRightEye, //右眼有遮挡
  56. TrackResultCodeOcclusionNose, //鼻子有遮挡
  57. TrackResultCodeOcclusionMouth, //嘴巴有遮挡
  58. TrackResultCodeOcclusionLeftContour, //左脸颊有遮挡
  59. TrackResultCodeOcclusionRightContour, //右脸颊有遮挡
  60. TrackResultCodeOcclusionChinCoutour, //下颚有遮挡
  61. TrackResultCodeVerifyInitError, //鉴权失败
  62. TrackResultCodeVerifyDecryptError,
  63. TrackResultCodeVerifyInfoFormatError,
  64. TrackResultCodeVerifyExpired,
  65. TrackResultCodeVerifyMissRequiredInfo,
  66. TrackResultCodeVerifyInfoCheckError,
  67. TrackResultCodeVerifyLocalFileError,
  68. TrackResultCodeVerifyRemoteDataError,
  69. TrackResultCodeUnknowType //未知类型
  70. };
  71. @class FaceInfo;
  72. @class FaceLivenessState;
  73. @class FaceCropImageInfo;
  74. @interface FaceSDKManager : NSObject
  75. /* 超时时间 */
  76. @property (nonatomic, assign) CGFloat conditionTimeout;
  77. /* 语音超时*/
  78. @property (nonatomic, assign) CGFloat intervalOfVoiceRemind;
  79. /* 输出图像个数 */
  80. @property (nonatomic, assign) int imageNum;
  81. /* 图像加密类型,默认0 */
  82. @property (nonatomic, assign) int imageEncrypteType;
  83. + (instancetype)sharedInstance;
  84. /**
  85. * 获取版本号
  86. */
  87. - (NSString *)getVersion;
  88. /**
  89. * 获取设备zid 公安验证上传
  90. */
  91. - (NSString *)getZtoken;
  92. /**
  93. * SDK鉴权方法-文件授权
  94. * SDK鉴权方法 必须在使用其他方法之前设置,否则会导致SDK不可用
  95. *
  96. * @param licenseID 授权ID
  97. * @param licensePath 本地鉴权文件路径
  98. * @param remoteAuthorize 是否远程更新过期鉴权文件
  99. */
  100. - (void)setLicenseID:(NSString *)licenseID andLocalLicenceFile:(NSString *)licensePath andRemoteAuthorize:(BOOL)remoteAuthorize;
  101. /**
  102. * 初始化采集功能
  103. */
  104. - (int) initCollect;
  105. /**
  106. * 卸载采集功能
  107. */
  108. - (int)uninitCollect;
  109. /**
  110. * 判断授权是否通过,true 表示通过,false 表示不通过
  111. */
  112. - (BOOL)canWork;
  113. /**
  114. * 设置预测库耗能模式
  115. * 默认 LITE_POWER_NO_BIND
  116. */
  117. - (void)setLitePower:(int)litePower;
  118. /**
  119. * 需要检测的最大人脸数目
  120. * 默认1
  121. */
  122. - (void)setMaxDetectNum:(int)detectNum ;
  123. /**
  124. * 需要检测的最小人脸大小
  125. * 默认40
  126. */
  127. - (void)setMinFaceSize:(int)width;
  128. /**
  129. * 人脸置信度阈值(检测分值大于该阈值认为是人脸
  130. * RGB
  131. * 默认 0.5f
  132. */
  133. - (void)setNotFaceThreshold:(CGFloat)thr ;
  134. /**
  135. * 质量检测遮挡阈值
  136. * 默认0.5
  137. */
  138. - (void)setOccluThreshold:(CGFloat)thr ;
  139. /**
  140. * 质量检测光照阈值
  141. * 默认100
  142. */
  143. - (void)setIllumThreshold:(CGFloat)thr ;
  144. /**
  145. * 质量检测模糊阈值
  146. * 默认0.5
  147. */
  148. - (void)setBlurThreshold:(CGFloat)thr ;
  149. /**
  150. * 姿态检测阈值
  151. * 默认pitch=12,yaw=12,row=10
  152. */
  153. - (void)setEulurAngleThrPitch:(float)pitch yaw:(float)yaw roll:(float)roll ;
  154. /**
  155. * 输出图像个数
  156. * 默认3
  157. */
  158. - (void)setMaxCropImageNum:(int)imageNum ;
  159. /**
  160. * 输出图像宽,设置为有效值(大于0)则对图像进行缩放,否则输出原图抠图结果
  161. * 默认 480
  162. */
  163. - (void)setCropFaceSizeWidth:(CGFloat)width ;
  164. /**
  165. * 输出图像高,设置为有效值(大于0)则对图像进行缩放,否则输出原图抠图结果
  166. * 默认 680
  167. */
  168. - (void)setCropFaceSizeHeight:(CGFloat)height ;
  169. /**
  170. * 输出图像,下巴扩展,大于等于0,0:不进行扩展
  171. * 默认0.1
  172. */
  173. - (void)setCropChinExtend:(CGFloat)chinExtend ;
  174. /**
  175. * 输出图像,额头扩展,大于等于0,0:不进行扩展
  176. * 默认0.2
  177. */
  178. - (void)setCropForeheadExtend:(CGFloat)foreheadExtend ;
  179. /**
  180. * 输出图像,人脸框与背景比例,大于等于1,1:不进行扩展
  181. * 默认1.5f
  182. */
  183. - (void)setCropEnlargeRatio:(float)cropEnlargeRatio;
  184. /**
  185. * 动作超时配置
  186. */
  187. - (void)setConditionTimeout:(CGFloat)timeout ;
  188. /**
  189. * 语音间隔提醒配置
  190. */
  191. - (void)setIntervalOfVoiceRemind:(CGFloat)timeout;
  192. /**
  193. * 是否开启静默活体,默认false
  194. */
  195. // - (void)setIsCheckSilentLive:(BOOL)isCheck;
  196. /**
  197. * 静默活体阈值配置,默认0.8。
  198. * 大于阈值返回图片,低于阈值返回未检测到人脸
  199. */
  200. // - (void)setSilentLiveThreshold:(CGFloat)thr ;
  201. /**
  202. * 是否开启口罩检测,非动作活体检测模型true,动作活体检测模型false
  203. */
  204. - (void)setIsCheckMouthMask:(BOOL)isCheck;
  205. /**
  206. * 口罩检测阈值配置,默认0.8。
  207. * 大于阈值判定为戴口罩,低于阈值判定为未戴口罩
  208. */
  209. - (void)setMouthMaskThreshold:(CGFloat)thr ;
  210. /**
  211. * 设置原始图片缩放比例,默认1不缩放,scale 阈值0~1
  212. */
  213. - (void)setImageWithScale:(CGFloat)scale;
  214. /**
  215. * 设置图片加密类型,type=0 基于base64 加密;type=1 基于百度安全算法加密
  216. */
  217. - (void)setImageEncrypteWithType:(int) type;
  218. /**
  219. * 采集动作验证
  220. * @param image 检测的图片
  221. * @param isOriginal 是否返回原始图片
  222. * @param completion 判断采集是否完成,人脸信息状态是否正常
  223. */
  224. - (void)detectWithImage:(UIImage *)image isRreturnOriginalValue:(BOOL) isOriginal completion:(void (^)(FaceInfo *faceinfo, ResultCode resultCode))completion;
  225. /**
  226. * 动作活体动作验证
  227. * @param image 检测的图片
  228. * @param actionLiveType 当前要求做的动作
  229. * @param completion 判断当前动作是否完成,人脸信息状态是否正常
  230. */
  231. - (void)livenessWithImage:(UIImage *)image withAction:(FaceLivenessActionType)actionLiveType completion:(void (^)(FaceInfo *faceinfo, FaceLivenessState *state, ResultCode resultCode))completion;
  232. @end
  233. @interface FaceLivenessState : NSObject
  234. /**
  235. * 动作活体-眨眨眼
  236. */
  237. @property(nonatomic, assign) BOOL isLiveEye;
  238. /**
  239. * 动作活体-张张嘴
  240. */
  241. @property(nonatomic, assign) BOOL isLiveMouth;
  242. /**
  243. * 动作活体-向左转头
  244. */
  245. @property(nonatomic, assign) BOOL isLiveYawLeft;
  246. /**
  247. * 动作活体-向右转头
  248. */
  249. @property(nonatomic, assign) BOOL isLiveYawRight;
  250. /**
  251. * 动作活体-抬头
  252. */
  253. @property(nonatomic, assign) BOOL isLivePitchUp;
  254. /**
  255. * 动作活体-低头
  256. */
  257. @property(nonatomic, assign) BOOL isLivePitchDown;
  258. @end
  259. @interface FaceCropImageInfo : NSObject
  260. /**
  261. * 基于质量检测,姿态角度,对图片得分
  262. */
  263. @property (nonatomic, assign) float qualityScore;
  264. /**
  265. * 离线RGB 静默活体得分
  266. */
  267. @property (nonatomic,assign) float silentliveScore;
  268. /**
  269. * 采集到的矫正,调整宽高图片,会有宽高
  270. */
  271. @property (nonatomic ,strong) UIImage *cropImageWithBlack;
  272. /**
  273. * 加密采集到的矫正,调整宽高图片,会有宽高
  274. */
  275. @property (nonatomic ,strong) NSString *cropImageWithBlackEncryptStr;
  276. /**
  277. * 原始图片
  278. */
  279. @property (nonatomic ,strong) UIImage *originalImage;
  280. /**
  281. * 加密原始图片
  282. */
  283. @property (nonatomic ,strong) NSString *originalImageEncryptStr;
  284. /**
  285. * 排序规则
  286. */
  287. - (NSComparisonResult)compareWithImageInfo:(FaceCropImageInfo *)info;
  288. @end
  289. @interface FaceInfo : NSObject
  290. /**
  291. * 人脸在图片中的位置
  292. */
  293. @property (nonatomic, assign) CGRect faceRect;
  294. /**
  295. * 人脸track 中的faceid
  296. */
  297. @property (nonatomic, assign) NSInteger faceId;
  298. /**
  299. * 人脸72关键点
  300. */
  301. @property (nonatomic, strong) NSArray * landMarks;
  302. /**
  303. * 人脸角度
  304. */
  305. @property (nonatomic, assign) float angle;
  306. /**
  307. * 人脸质量-光照置信度,通过quality 方法调用获取
  308. */
  309. @property (nonatomic,assign) float illum;
  310. /**
  311. * 人脸质量-模糊置信度,通过quality 方法调用获取
  312. */
  313. @property (nonatomic,assign) float blur;
  314. /**
  315. * 人脸上下偏转角,通过headpose 方法调用获取
  316. */
  317. @property (nonatomic, assign) float pitch;
  318. /**
  319. * 人脸左右偏转角,通过headpose 方法调用获取
  320. */
  321. @property (nonatomic, assign) float yaw;
  322. /**
  323. * 人脸平行平面内的头部旋转角,通过headpose 方法调用获取
  324. */
  325. @property (nonatomic, assign) float roll;
  326. /**
  327. * 离线RGB 静默活体得分
  328. */
  329. @property (nonatomic,assign) float silentliveScore;
  330. /**
  331. * 人脸检测得分
  332. */
  333. @property (nonatomic, assign) CGFloat score;
  334. /**
  335. * 输出图片结构体,包含图片质量分数,裁剪没有黑边的图片,裁剪有黑边的图片,未裁剪图片,原始图
  336. */
  337. @property (nonatomic, strong) FaceCropImageInfo * cropImageInfo;
  338. @end