基于JAVA平台使用百度人脸识别API

一、申请百度API人脸识别的使用权利

      http://ai.baidu.com/tech/face(点击进入官方网站,然后找到产品服务-人脸识别)

二、注册百度账号,并且申请人脸识别的使用权(一般几分钟就可以了,不会太久),获取以下参数,为调用API做准备

AppID
API Key
Secret Key


三、接下来,开始敲代码调用百度API了,具体技术需要可以查看相关文档(https://ai.baidu.com/docs#/Face-Detect/top

      详细代码如下

package com;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONObject;

import com.baidu.aip.face.AipFace;

public class BaiduFace {

	//以下参数分别对应着意见申请好的AppID、API Key 以及 Secret Key
	public static final String APP_ID = "输入AppID";
	public static final String API_KEY = "输入API Key";
	public static final String SECRET_KEY = "输入Secret Key";
	
	public static void main(String[] args) {
		AipFace client = new AipFace(APP_ID , API_KEY , SECRET_KEY);
		client.setConnectionTimeoutInMillis(2000);
		client.setSocketTimeoutInMillis(60000);
		String img_1 = "F:/img/1.jpg";  //需要进行人脸识别的图像位置
		String img_2 = "F:/img/2.jpg";  //需要进行人脸识别的图像位置
	    ArrayList pathArray = new ArrayList();
	    pathArray.add(img_1);
	    pathArray.add(img_2);
	    JSONObject response = client.match(pathArray ,  new HashMap());
	    System.out.println(response.toString()); //输出的是JSON格式
	}
}

输出:{"result":[{"score":64.786140441895,"index_i":"0","index_j":"1"}],"log_id":3877673471041318,"result_num":1}

其中,score代表相似度,相似度越高,说明两张图片的人脸越像是同一个人。

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值