自己写一个控制台人脸识别程序
其中用到的技术:IO文件流,api,json,集合
package com.aa;
/***********************************************
@作者: FW
@创建时间:2019年2月22日 下午12:00:01
@版本:v1.0
@描述:
***********************************************/
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import javax.net.ssl.SSLException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public class FaceTest {
public static void main(String[] args) throws Exception{
File file = new File("C:\\Users\\vision\\Pictures\\Camera Roll\\56.jpg");
byte[] buff = getBytesFromFile(file);
String url = "https://api-cn.faceplusplus.com/facepp/v3/detect";
HashMap<String, String> map = new HashMap<>();
HashMap<String, byte[]> byteMap = new HashMap<>();
map.put("api_key", "****************************");
map.put("api_secret", "********************************");
map.put("return_landmark", "0");
map.put("return_attributes", "gender,age,smiling,eyestatus,beauty,skinstatus");
byteMap.put("image_file", buff);
try{
byte[] bacd = post(url, map, byteMap);
String str = new String(bacd);
System.out.println(str);
JSONObject jsonObject=J