人脸识别比对 java_Java通过摄像头捕捉人脸识别和已有的照片进行相似度比对(OpenCV + face++)...

这个博客介绍了如何在Java中利用OpenCV和Face++库进行人脸识别,包括从摄像头捕获图像、获取图像的face_token以及与预存照片进行相似度比对。示例代码展示了如何发送HTTP请求,处理响应,并通过API调用来实现功能。
摘要由CSDN通过智能技术生成

好像是face++,又好像不是,具体的忘记了,为了以后自己可以好找代码:

package com.common.face;

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.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.JSONArray;

import com.alibaba.fastjson.JSONObject;

/**

* 得到pic的face_token

*/

public class FacePlus {

public static void main(String[] args) throws Exception{

File file = new File("C:\\Users\\Administrator\\Desktop\\abc\\erwa.jpg");

byte[] buff = getBytesFromFile(file);

String url = "https://api-cn.faceplusplus.com/facepp/v3/detect";

HashMap map = new HashMap<>();

HashMap byteMap = new HashMap<>();

map.put("api_key", "NCZxjJtNcTsQJLNc_zhEp6OeWyC3OgW6");

map.put("api_secret", "X8ymk7AKMFWrWJP6RHr_NZOO9eZmAvzw");

map.put("return_landmark", "1");

map.put("return_attributes", "gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");

byteMap.put("image_file", buff);

try{

byte[] bacd = post(url, map, byteMap);

String str = new String(bacd);

System.out.println(str);

JSONObject jsonObject = JSONObject.parseObject(str);

JSONArray jsonArray = (JSONArray) jsonObject.get("faces");

JSONObject jsonfac = (JSONObject) jsonArray.get(jsonArray.size()-1);

String face_token = (String) jsonfac.get("face_token");

System.out.println(face_token);

}catch (Exception e) {

e.printStackTrace();

}

}

public static String getFaceId(byte[] buff){

String url = "https://api-cn.faceplusplus.com/facepp/v3/detect";

HashMap map = new HashMap<>();

HashMap byteMap = new HashMap<>();

map.put("api_key", "NCZxjJtNcTsQJLNc_zhEp6OeWyC3OgW6");

map.put("api_secret", "X8ymk7AKMFWrWJP6RHr_NZOO9eZmAvzw");

map.put("return_landmark", "1");

map.put("return_attributes", "gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");

byteMap.put("image_file", buff);

String face_token = "";

try{

byte[] bacd = post(url, map, byteMap);

String str = new String(bacd);

System.out.println("str:"+str);

JSONObject jsonObject = JSONObject.parseObject(str);

JSONArray jsonArray = (JSONArray) jsonObject.get("faces");

int size = jsonArray.size();

System.out.println("size:"+size);

if(size == 0){

return "-1";

}

JSONObject jsonfac = (JSONObject) jsonArray.get(size-1);

face_token = (String) jsonfac.get("face_token");

}catch (Exception e) {

e.printStackTrace();

}

return face_token;

}

private final static int CONNECT_TI

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值