AI's most recognized project among the people may be picture effects
In this activity, Xiaoshuai will take developers to quickly start the skin color detection API
All developers must read the interface documents
Interface documentation https://ai.baidu.com/ai-doc/FACE/2k7zyhuev
How to create an application. Remember to read the access guide in the document when obtaining the access token. Officials have given graphic tutorials. Xiaoshuai, I won't repeat it here. AI access guide
Application for test invitation capacity opening
Log in to the console to fill in the work order submission https://ticket.bce.baidu.com/?_=1583756196861&fromai=1#/ticket/list
Note: information needs to be provided, including appid, interface to be opened, company name, contact person and telephone number, and specific application scenarios.
Introduction to interface capability
Business capability: detect the skin color of the face in the picture through AI technology. It supports gears 1-6. The smaller the number, the lighter the color
- Skin color detection: support multi gear skin color detection. The smaller the number, the lighter the color
- Picture quality control: judge the quality of the input picture, and support standard customization and control including the size, definition, illumination, etc. of the picture itself
- Face angle judgment: judge various pose angles of the face in the picture
Interface call
Get accesstoken (browser)
Replace the API Key and Secret Key with the information of the application you created
https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=API Key&client_secret=Secret Key
Use the fastest way to get AccessToken
Replace the above URL. Paste it directly into the browser address bar and press enter. Get the following fields. We just need access_ Value after token
{ "refresh_token": "25.6973e8f0835d6458b46a12b52f008a1b.315360000.1903242650.282335-123456798", "expires_in": 2592000, "session_key": "9mzdDxEUo4Lny4jBhrHfOfoZgeqAphy5iTvSQgDWubDduWwGNzoQpCLC+1IEnGDlbFAD4q1Roty5O2DrloahXAgLuwZH", "access_token": "24.458cd6570f77221a5837e0185dce0ab6.2592000.1590474650.282335-123456798", "scope": "............", "session_secret": "878013faa3981961862ca61280eaa9e9" }
Get access_ The value after token is saved for standby
Code request interface
Additional third-party library fastjson is required
/** * @author Xiaoshuai * @className SkinColorSample * @Description Skin color detection * @Date 2020/4/26 **/ public class SkinColorSample { /** * Important tool classes required in code * FileUtil,Base64Util,HttpUtil Please from * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72 * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2 * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3 * download */ public static void main(String[] args) throws Exception { //Please replace the API address with the API address provided by skin color detection String url ="https://aip.baidubce.com/rest/2.0/face/v1/skin_color"; //Please fill in the applied APPID String appid = "[Applied AppID]"; //Picture type base64: base64 value of picture; URL: the URL of the picture (the download time may be too long due to network and other reasons when downloading the picture) FACE_TOKEN: face identification String image_type = "BASE64"; //access_ For the token obtaining method, please refer to the API instructions. Please pay attention to access_ The valid period of the token is 30 days String access_token="[access_token]"; //Modify the picture address and test different pictures byte[] file = FileUtil.readFileByBytes("[Local picture address]"); //Parameter image: base64 encoding of image String image = Base64Util.encode(file); //Place request parameters in the Body String params = "{\"appid\":\""+appid+"\",\"image_type\":\""+image_type+"\",\"image\":\""+image+"\"}"; String result = HttpUtil.post(url, access_token, params); //Output identification results System.out.println(result); //Output skin color JSONObject object = JSON.parseObject(result); //Get the first face_list Object face_list = object.getJSONObject("result").getJSONArray("face_list").get(0); //First face_list to JSONObject JSONObject skin = JSON.parseObject(face_list.toString()); //Get the value of color in the skin object, that is, the smaller the skin color level value, the lighter the skin color System.out.println(skin.getJSONObject("skin").get("color")); } }
Contents of console output
1 is the skin color grade

null--->[HTTP/1.1 200 OK] Server--->[Apache] Access-Control-Allow-Origin--->[*] Access-Control-Allow-Methods--->[GET,POST,OPTIONS] Connection--->[keep-alive] P3p--->[CP=" OTI DSP COR IVA OUR IND COM ", CP=" OTI DSP COR IVA OUR IND COM "] Date--->[Sun, 26 Apr 2020 06:55:14 GMT] Access-Control-Allow-Headers--->[X-Requested-With] Appid--->[18904875] Tracecode--->[33143086990229861130042614] Vary--->[Accept-Encoding] Set-Cookie--->[BAIDUID=8D8D939FA8FDA44F6A54BB25D6F2137C:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2145916555; path=/; domain=.baidu.com; version=1, BAIDUID=1411AFDFE1A4CEA572EA46302B9FE029:FG=1; expires=Mon, 26-Apr-21 06:55:14 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1] Content-Length--->[279] Content-Type--->[application/json] result:{"error_code":0,"error_msg":"SUCCESS","log_id":2584651013510,"timestamp":1587884114,"cached":0,"result":{"face_num":1,"face_list":[{"face_token":"9ac4c972ff3d48afd4e6b6631be93202","location":{"left":444.61,"top":483.45,"width":420,"height":424,"degree":-2},"skin":{"color":1}}]}} 1
{ "error_code":0, "error_msg":"SUCCESS", "log_id":2584651013510, "timestamp":1587884114, "cached":0, "result":{ "face_num":1, "face_list":[ { "face_token":"9ac4c972ff3d48afd4e6b6631be93202", "location":{ "left":444.61, "top":483.45, "width":420, "height":424, "degree":-2 }, "skin":{ "color":1 } } ] } }
Skin color grading
Skin color grading, 1 ~ 6, the smaller the skin color, the lighter the skin color 1-6 the Chinese descriptions given by Xiao Shuai are (for reference only): very shallow, shallow, medium, deep, very deep and unfathomable
Online experience

Application scenario
Intelligent medical beauty It supports uploading or cooperating with the acquisition tool to take photos in real time, and then conduct in-depth analysis of skin color and quality to realize comparison and skin color gear output Interactive entertainment It can be used in various short video products or interactive marketing programs to provide interesting experience Large screen interaction It can be used for large screen interactive experience in various shopping malls. Recommend different skin care products according to skin color
Opinions & Suggestions
1. The interface does not evaluate gender separately 2. The returned skin color level is too simple (it is recommended that when color is 1, the corresponding confidence score can be given)