FacePlusPlus人脸识别
来源:互联网 发布:网络销售做股票违法吗 编辑:程序博客网 时间:2024/06/02 08:48
API功能
/detection/detect
描述
检测给定图片(Image)中的所有人脸(Face)的位置和相应的面部属性
目前面部属性包括性别(gender), 年龄(age), 种族(race), 微笑程度(smiling), 眼镜(glass)和姿势(pose)
若结果的face_id没有被加入任何faceset/person之中,则在72小时之后过期被自动清除。
参数
返回值说明
包含微笑程度分析结果,value的值为0-100的实数,越大表示微笑程度越高
glassobject包含眼镜佩戴分析结果,value的值为None/Dark/Normal, confidence表示置信度
poseobject包含脸部姿势分析结果,包括pitch_angle, roll_angle, yaw_angle,分别对应抬头,旋转(平面旋转),摇头。单位为角度。
调用示例
http://apicn.faceplusplus.com/v2/detection/detect?api_key=YOUR_API_KEY&api_secret=YOUR_API_SECRET&url=http%3A%2F%2Ffaceplusplus.com%2Fstatic%2Fimg%2Fdemo%2F1.jpg&attribute=glass,pose,gender,age,race,smiling
JSON 示例
{ "face": [ { "attribute": { "age": { "range": 5, "value": 23 }, "gender": { "confidence": 99.9999, "value": "Female" }, "glass": { "confidence": 99.945, "value": "None" }, "pose": { "pitch_angle": { "value": 17 }, "roll_angle": { "value": 0.735735 }, "yaw_angle": { "value": -2 } }, "race": { "confidence": 99.6121, "value": "Asian" }, "smiling": { "value": 4.86501 } }, "face_id": "17233b4b1b51ac91e391e5afe130eb78", "position": { "center": { "x": 49.4, "y": 37.6 }, "eye_left": { "x": 43.3692, "y": 30.8192 }, "eye_right": { "x": 56.5606, "y": 30.9886 }, "height": 26.8, "mouth_left": { "x": 46.1326, "y": 44.9468 }, "mouth_right": { "x": 54.2592, "y": 44.6282 }, "nose": { "x": 49.9404, "y": 38.8484 }, "width": 26.8 }, "tag": "" } ], "img_height": 500, "img_id": "22fd9efc64c87e00224c33dd8718eec7", "img_width": 500, "session_id": "38047ad0f0b34c7e8c6efb6ba39ed355", "url": "http://www.faceplusplus.com.cn/wp-content/themes/faceplusplus/assets/img/demo/1.jpg?v=4"}
错误列表
package org.jiahao.weixin.util; import java.util.ArrayList;import java.util.Collections;import java.util.List; import net.sf.json.JSONArray;import net.sf.json.JSONObject; import org.jiahao.weixin.face.Face; /** * 人脸识别FacePlusPlus工具类 * @author Alvin * */public class FacePlusPlusUtil { public static String detectFace(String imageUrl) { // 拼装请求地址 String requestUrl = "http://apicn.faceplusplus.com/v2/detection/detect?api_key=YOUR_API_KEY&api_secret=YOUR_API_SECRET&url=URL&attribute=glass,pose,gender,age,race,smiling"; requestUrl = requestUrl.replace("YOUR_API_KEY", "e93513e749c2a70a297189b232f22f1d"); requestUrl = requestUrl.replace("YOUR_API_SECRET", "sZs-D_kjQ3kfWGqcPNcv70rqgU-d-GBM"); requestUrl = requestUrl.replace("URL", CommonUtil.urlEncodeUTF8(imageUrl)); // 发起请求 String respJson = CommonUtil.httpRequest(requestUrl, "GET", null); // 获取Face数组 JSONArray faceArray = (JSONArray)JSONObject.fromObject(respJson).get("face"); List<Face> faceList = new ArrayList<Face>(); // 遍历检测到的人脸 for(int i = 0; i < faceArray.size(); i++) { JSONObject faceObject = (JSONObject)faceArray.get(i); JSONObject attributeObject = faceObject.getJSONObject("attribute"); JSONObject positionObject = faceObject.getJSONObject("position"); Face face = new Face(); face.setFaceId(faceObject.getString("face_id")); face.setAgeValue(attributeObject.getJSONObject("age").getInt("value")); face.setAgeRange(attributeObject.getJSONObject("age").getInt("range")); face.setGenderValue(genderConvert(attributeObject.getJSONObject("gender").getString("value"))); face.setGenderConfidence(attributeObject.getJSONObject("gender").getDouble("confidence")); face.setRaceValue(raceConvert(attributeObject.getJSONObject("race").getString("value"))); face.setRaceConfidence(attributeObject.getJSONObject("race").getDouble("confidence")); face.setSmilingValue(attributeObject.getJSONObject("smiling").getDouble("value")); face.setCenterX(positionObject.getJSONObject("center").getDouble("x")); face.setCenterY(positionObject.getJSONObject("center").getDouble("y")); faceList.add(face); } Collections.sort(faceList); StringBuffer buffer = new StringBuffer(); // 检测到1张人脸 if(1 == faceList.size()) { buffer.append("共检测到").append(faceList.size()).append("张人脸\n\n"); for(Face face : faceList) { // 人种 buffer.append(face.getRaceValue()).append("人种,"); // 性别 buffer.append(face.getGenderValue()).append(","); // 年龄 buffer.append(face.getAgeValue()).append("岁左右"); } } // 检测到多张人脸 else if(faceList.size() > 1) { buffer.append("共检测到").append(faceList.size()).append("张人脸,按脸部中心位置从左到右依次为:\n\n"); for(Face face : faceList) { // 人种 buffer.append(face.getRaceValue()).append("人种,"); // 性别 buffer.append(face.getGenderValue()).append(","); // 年龄 buffer.append(face.getAgeValue()).append("岁左右\n"); } } else { buffer.append("你确定你发的是人?"); } return buffer.toString(); } /** * 将 Male/Female 转换成 男性/女性 * @param gender * @return */ private static String genderConvert(String gender) { String result = "男性"; if(gender.equals("Female")) { result = "女性"; } return result; } /** * 将 Asian/White/Black 转换成 黄色/白色/黑色 * @param race * @return */ private static String raceConvert(String race) { String result = "黄色"; if(race.equals("Asian")) { result = "黄色"; } else if(race.equals("White")) { result = "白色"; } else if(race.equals("Black")) { result = "黑色"; } return result; } public static void main(String[] args) { String str = FacePlusPlusUtil.detectFace("http://mmbiz.qpic.cn/mmbiz/lLTibpXzX33grSReqBZGr0NcnVclxdzGH9TvDztcjIseDFmPUNz3IprJITdvib9TicZU0iaLKlibhpxYTWibClQcQF0w/0.jpg"); System.out.println(str); }}
0 0
- FacePlusPlus人脸识别
- faceplusplus 免费人脸识别云服务
- 【Android】【Demo】faceplusplus.apitest
- 语音识别&人脸识别
- 【人脸识别】初识人脸识别
- 【人脸识别】初识人脸识别
- OpenCV的行人识别&人脸识别
- 图片识别之人脸识别API
- OpenCV的行人识别&人脸识别
- IOS人脸识别和二维码识别
- 人脸识别之颜色识别
- Face++ 人脸识别,身份识别集成
- 人脸识别:(抓拍+识别)
- 人脸识别的发展方向:蒙面识别
- 人脸识别
- 人脸识别
- 人脸识别算法
- 简单人脸识别
- 在C#中截取指定长度的中文字符串
- 第二周【项目0】宣告主权
- 【Qt开发】QSplitter的使用和设置
- Filter中获取Spring的bean
- Https证书制作方法
- FacePlusPlus人脸识别
- 圆背景组件以及数字红点
- angularjs2 四
- 项目1-c/c++语言中函数参数传递的三中方式
- 共同父域下的单点登录
- 十条jQuery代码片段助力Web开发效率提升
- 深入理解RunLoop
- 复习 类和对象
- Hi3516A开发--USB PCB 设计建议