Android
Function Description
Input a photo containing a face and output facial feature information of the person, including eyes, eyebrows, hairstyle, skin color, gender, age, etc. This interface requires internet connection, and the SDK will upload the photo to the server for parsing.
Integration Guide
First, you need to integrate Tencent Effect SDK, please refer to Independent Integration of Tencent Effect for details.
Interface Description
XMagicApi.java
public void getFaceFeatureFromPhoto(Bitmap bitmap, FaceFeatureListener listener);
Parameter bitmap: Please try to make the face in the center of the picture. It is recommended that the picture only contains one face. If there are multiple faces, the SDK will randomly select one. It is recommended that the short side of the photo be greater than or equal to 500px. A small size will affect the recognition effect.
Parameter FaceFeatureListener, returns the recognition result.
public interface FaceFeatureListener {void onError(int errCode, String msg);void onFinish(FaceDetailAttributesInfo faceInfo);}
onError callback: This interface will be called back when the parsing fails, and the error codes are as follows.
public static final int ERROR_NO_AUTH = 1; // No permissionpublic static final int ERROR_RES_INVALID = 5;//Invalid Avatar material pathpublic static final int ERROR_PHOTO_INVALID = 10;//Failed to read the photopublic static final int ERROR_NETWORK_REQUEST_FAILED = 20; // Network request failedpublic static final int ERROR_DATA_PARSE_FAILED = 30; // Failed to parse network return datapublic static final int ERROR_ANALYZE_FAILED = 40; // Face analysis failedpublic static final int ERROR_AVATAR_SOURCE_DATA_EMPTY = 50; // Failed to load Avatar source data
onFinish callback: This interface will be called back when the parsing is successful, and FaceDetailAttributesInfo is explained as follows.
public static class FaceDetailAttributesInfo {public int age; //[0,100]public int emotion; //0: natural, 1: happy, 2: surprised, 3: angry, 4: sad, 5: disgusted, 6: afraidpublic Eye eye; // Eye informationpublic Eyebrow eyebrow; // Eyebrow informationpublic int gender; // Gender information. -1: not recognized, 0: male, 1: female.public Hair hair; // Hairstyle informationpublic Hat hat; // Hat informationpublic int mask; // Whether there is a mask. -1: not recognized, 0: no, 1: yes.public int moustache; // Moustache information. -1: not recognized, 0: no moustache, 1: has moustache.public int nose; // Nose information. -1: not recognized, 0: upturned nose, 1: hooked nose, 2: normal, 3: round nose.public int shape; // Face shape information. -1: not recognized, 0: square face, 1: triangular face, 2: oval face, 3: heart-shaped face, 4: round face.public int skin; // Skin color information. -1: not recognized, 0: yellow skin, 1: brown skin, 2: black skin, 3: white skin.public int smile; // Smile degree, [0,100].}public static class Eye {public int eyelidType; // Whether double eyelids are recognized. -1: not recognized, 0: no, 1: yes.public int eyeSize; // Eye size. -1: not recognized, 0: small eyes, 1: normal eyes, 2: big eyes.public int glass; // Whether wearing glasses is recognized. -1: not recognized, 0: no glasses, 1: normal glasses, 2: sunglasses.public int eyeOpen; // Recognize the opening and closing state of the eyes. -1: not recognized, 0: open, 1: closed.}public static class Eyebrow {public int eyebrowLength; // Eyebrow length. 0: short eyebrows, 1: long eyebrows.public int eyebrowDensity; // Eyebrow density. 0: light eyebrows, 1: thick eyebrows.public int eyebrowCurve; // Eyebrow curvature. 0: not curved, 1: curved eyebrows.}public static class Hair {public int length; // Hair length information. 0: bald, 1: short hair, 2: medium hair, 3: long hair, 4: tied hair.public int bang; // Bangs information. 0: no bangs, 1: with bangs.public int color; // Hair color information. 0: black, 1: golden, 2: brown, 3: gray-white.}public static class Hat {public int style; // Hat wearing status information. 0: no hat, 1: normal hat, 2: helmet, 3: security hat.public int color; // Hat color. 0: no hat, 1: red series, 2: yellow series, 3: blue series, 4: black series, 5: gray-white series, 6: mixed color series.}