功能说明
该接口可通过上传包含人脸的照片获取人物面部特征信息,包括眼睛、眉毛、发型、肤色、性别、年龄等。该接口需要联网环境下才可通过 SDK 把照片上传到 Server 端进行解析。
集成指引
接口说明
接口所在类:XMagic.h
+ (void)getFaceFeatureFromPhoto:(UIImage * _Nullable)image success:(nullable void (^)(FaceDetailAttributesinfo *_Nullable faceInfo))success failure:(nullable void (^)(NSInteger errorCode, NSString *_Nullable msg))failure;
参数 image:请尽量让人脸位于画面中间,建议画面中只包含一个人脸。如果有多个人脸,SDK会随机选择一个。建议照片的短边大于等于500px,尺寸过小会影响识别效果。
参数 success、failure:返回识别的结果。
// 成功回调,返回识别结果(nullable void (^)(FaceDetailAttributesinfo *_Nullable faceInfo))success;// 失败回调(nullable void (^)(NSInteger errorCode, NSString *_Nullable msg))failure;
failure 回调:解析失败时会回调此接口,错误码如下。
typedef NS_ENUM(NSInteger, TEAvatarErrorCode) {TEAvatarErrorCodeNoAuth = 1, // 没有权限TEAvatarErrorCodeResInValid = 5, // 传入的Avatar素材路径无效TEAvatarErrorCodePhotoInValid = 10, // 读取照片失败TEAvatarErrorCodeNetReqFailed = 20, // 网络请求失败TEAvatarErrorCodeNetResParseFailed = 30, // 网络返回数据解析失败TEAvatarErrorCodeAnalyzeFailed = 40, // 人脸分析失败TEAvatarErrorCodeAvatarSourceEmpty = 50 // 加载Avatar源数据失败};
success 回调:解析成功时回调此接口,FaceDetailAttributesInfo 说明如下。
/// @brief 拍照捏脸配置数据 Snapping face configuration data// 眼睛 eye@interface Eye : NSObject/**识别是否双眼皮。-1:没识别,0:无,1:有Identify whether double eyelid. -1: not recognized, 0: no, 1: yes*/@property (nonatomic, assign) NSInteger eyelidType;/**眼睛大小。-1:没识别,0:小眼睛,1:普通眼睛,2:大眼睛eye size. -1: No recognition, 0: Small eyes, 1: Normal eyes, 2: Big eyes*/@property (nonatomic, assign) NSInteger eyeSize;/**识别是否佩戴眼镜。-1:没识别,0:无眼镜,1:普通眼镜,2:墨镜Identify whether glasses are worn. -1: No recognition, 0: No glasses, 1: Ordinary glasses, 2: Sunglasses*/@property (nonatomic, assign) NSInteger glass;/**识别眼睛是否睁开。-1:没识别,0:睁开,1:闭眼Identify if eyes are open. -1: No recognition, 0: Open, 1: Closed eyes*/@property (nonatomic, assign) NSInteger eyeOpen;@end// 眉毛 Eyebrow@interface Eyebrow : NSObject/**眉毛长短。0:短眉毛,1:长眉毛The length of the eyebrows. 0: short eyebrows, 1: long eyebrows*/@property (nonatomic, assign) NSInteger eyebrowLength;/**眉毛浓密。0:淡眉,1:浓眉thick eyebrows. 0: light eyebrow, 1: thick eyebrow*/@property (nonatomic, assign) NSInteger eyebrowDensith;/**眉毛弯曲。0:不弯,1:弯眉The eyebrows are curved. 0: not curved, 1: curved eyebrow*/@property (nonatomic, assign) NSInteger eyebrowCurve;@end// 头发 Hair@interface Hair : NSObject/**头发长度信息。0:光头,1:短发,2:中发,3:长发,4:绑发Hair length information. 0: bald, 1: short hair, 2: medium hair, 3: long hair, 4: tied hair*/@property (nonatomic, assign) NSInteger length;/**刘海信息。0:无刘海,1:有刘海Bangs information. 0: no bangs, 1: with bangs*/@property (nonatomic, assign) NSInteger bang;/**头发颜色信息。0:黑色,1:金色,2:棕色,3:灰白色Hair color information. 0: black, 1: gold, 2: brown, 3: off-white*/@property (nonatomic, assign) NSInteger color;@end// 帽子 Hat@interface Hat : NSObject/**帽子佩戴状态。0:不戴帽子,1:普通帽子,2:头盔,3:保安帽子The state of wearing the hat. 0: no hat, 1: ordinary hat, 2: helmet, 3: security hat*/@property (nonatomic, assign) NSInteger style;/**帽子颜色。0:不戴帽子,1:红色系,2:黄色系,3:蓝色系,4:黑色系,5:灰白色系,6:混色系hat color. 0: no hat, 1: red, 2: yellow, 3: blue, 4: black, 5: off-white, 6: mixed color*/@property (nonatomic, assign) NSInteger color;@end@interface FaceDetailAttributesinfo : NSObject@property (nonatomic, assign) NSInteger age; // [0,100]/**0:自然,1:高兴,2:惊讶,3:生气,4:悲伤,5:厌恶,6:害怕0: Natural, 1: Happy, 2: Surprised, 3: Angry, 4: Sad, 5: Disgusted, 6: Scared*/@property (nonatomic, assign) NSInteger emotion;/**性别。-1:没识别,0:男性,1:女性gender. -1: not identified, 0: male, 1: female*/@property (nonatomic, assign) NSInteger gender;/**眼睛信息eye information*/@property (nonatomic, strong) Eye * _Nonnull eye;/**眉毛信息eyebrow information*/@property (nonatomic, strong) Eyebrow * _Nonnull eyebrow;/**头发信息hair information*/@property (nonatomic, strong) Hair * _Nonnull hair;/**帽子信息hat information*/@property (nonatomic, strong) Hat * _Nonnull hat;/**是否有口罩,-1:没识别,0:无,1:有Whether there is a mask, -1: no recognition, 0: no, 1: yes*/@property (nonatomic, assign) NSInteger mask;/**胡子信息。-1:没识别,0:无胡子,1:有胡子Beard information. -1: no recognition, 0: no beard, 1: beard*/@property (nonatomic, assign) NSInteger moustache;/**鼻子信息。-1:没识别,0:朝天鼻,1:鹰钩鼻,2:普通,3:圆鼻头nose information. -1: No recognition, 0: Upturned nose, 1: Hooked nose, 2: Normal, 3: Round nose*/@property (nonatomic, assign) NSInteger nose;/**脸型信息。-1:没识别,0:方脸,1:三角脸,2:鹅蛋脸,3:心形脸,4:圆脸face information. -1: No recognition, 0: Square face, 1: Triangular face, 2: Oval face, 3: Heart-shaped face, 4: Round face*/@property (nonatomic, assign) NSInteger shape;/**肤色信息。-1:没识别,0:黄色皮肤,1:棕色皮肤,2:黑色皮肤,3:白色皮肤Skin color information. -1: not identified, 0: yellow skin, 1: brown skin, 2: black skin, 3: white skin*/@property (nonatomic, assign) NSInteger skin;/**微笑程度。[0,100]Smile level [0,100]*/@property (nonatomic, assign) NSInteger smile;@end