一、需要了解的一些概念
(1)前沿生态-----图像识别技术
(2)人脸face_token
(3)人脸集合 faceSet
(4)人脸搜索
二、Web API
(1)注册账号
(2)登录账号
(3)入门学习
三、基于Java语言调用Detect API进行人脸识别测试
public class FaceTest {
public static void main(String[] args) throws Exception{
//设置需要识别图像 File file = new File("C:\\Users\\18902\\Desktop\\lym.jpg"); //获取图像信息 byte[] buff = getBytesFromFile(file); //准备一个URL对象:URL String url = "https://api-cn.faceplusplus.com/facepp/v3/detect"; HashMap<String, String> map = new HashMap<>(); HashMap<String, byte[]> byteMap = new HashMap<>(); //你在Face++官网创建的API_KEY map.put("api_key", "your api key"); map.put("api_secret", "your api secrect"); byteMap.put("image_file", buff); try{
byte[] bacd = post(url, map, byteMap); String str = new String(bacd); System.out.println(str); }catch (Exception e) {
e.printStackTrace(); } } private final static int CONNECT_TIME_OUT = 30000; private final static int READ_OUT_TIME = 50000; private static String boundaryString = getBoundary(); protected static byte[] post(String url, HashMap<String, String> map, HashMap<String, byte[]> fileMap) throws Exception {
HttpURLConnection conne; URL url1 = new URL(url); conne = (HttpURLConnection) url1.openConnection(); conne.setDoOutput(true); conne.setUseCaches(false); conne.setRequestMethod("POST"); conne.setConnectTimeout(CONNECT_TIME_OUT); conne.setReadTimeout(READ_OUT_TIME); conne.setRequestProperty("accept", "*/*"); conne.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundaryString); conne.setRequestProperty("connection", "Keep-Alive"); conne.setRequestProperty("user-agent", "Mozilla/4.0 (compatible;MSIE 6.0;Windows NT 5.1;SV1)"); DataOutputStream obos = new DataOutputStream(conne.getOutputStream()); Iterator iter = map.entrySet().iterator(); while(iter.hasNext()){
Map.Entry<String, String> entry = (Map.Entry) iter.next();