本文目录一览:
- 1、使用百度Ai进行人脸身份识别(公安验证)
- 2、用OpenCV开发人脸识别软件,用Java好还是用C/C++好
- 3、如何开发Java动态人脸识别
- 4、人脸识别系统使用java的开发
- 5、java 人脸识别sdk推荐个好用的?
- 6、java怎么实现人脸识别?
使用百度Ai进行人脸身份识别(公安验证)
import com.baidu.aip.util.Base64Util;
import com.enation.app.base.core.service.Exception.CreditAuthFaceException;
import com.enation.app.base.core.service.ICreditAuthManager;
import com.enation.app.base.core.util.AuthTokenService;
import com.enation.app.base.core.util.HttpClientUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import java.io.*;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageInputStream;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
/**
* 人脸识别service
* @param name
* @param id_card
* @param faceUrl
*/
@Override
public void face(String name, String id_card, String faceUrl) {
//调用接口获取tocken(有效期一个月)
String token = AuthTokenService.getAuth();
System.out.println("1:token:" + token);
//调用身份验证api地址
String url ="" + token;
File face=new File(faceUrl);
FileImageInputStream input =null;
byte[] data =null;
String base64Image =null;
try {
input =new FileImageInputStream(face);
ByteArrayOutputStream output =new ByteArrayOutputStream();
byte[] buf =new byte[1024];
int numBytesRead =0;
while ((numBytesRead = input.read(buf)) != -1) {
output.write(buf,0, numBytesRead);
}
data = output.toByteArray();
base64Image = Base64Util.encode(data);
System.out.println("4base64转码:"+base64Image);
}catch (IOException e) {
e.printStackTrace();
}finally {
try {
if (input !=null) {
input.close();
}
}catch (IOException e) {
e.printStackTrace();
}
}
Map headers =new HashMap();
headers.put("Content-Type","application/x-www-form-urlencoded");
Map bodys =new HashMap();
bodys.put("image", base64Image);
bodys.put("id_card_number", id_card);
bodys.put("name", name);
try {
CloseableHttpResponse response = HttpClientUtils.doHttpsPost(url, headers, bodys);
String result= HttpClientUtils.toString(response);
System.out.println("5返回json数据:" + result);
org.json.JSONObject jsonObject=new org.json.JSONObject(result);
System.out.println("jsonObject:"+jsonObject);
Object jsonResult = jsonObject.get("result");
Float floatResult = Float.parseFloat(jsonResult.toString());
if (floatResult =0.80) {
System.out.println("floatResult:"+floatResult+"人脸身份验证成功");
}else {
System.out.println("floatResult:"+floatResult+"人脸身份验证失败");
throw new CreditAuthFaceException("人脸身份验证失败");
}
}catch (Exception e) {
e.printStackTrace();
System.out.println("异常输出");
throw new CreditAuthFaceException("人脸认证失败");
}
}
用OpenCV开发人脸识别软件,用Java好还是用C/C++好
我去年就用opencv开发的android手机端的关于人脸识别的增强现实应用。我可以很明确的告诉你,java的opencv顶多调用摄像头用,图像处理都用c++的opencv。对于opencv的开发,不管从开发效率还是执行效率,绝对是c++。java版的opencv想都不要想。
如何开发Java动态人脸识别
1.环境搭建
整个项目的结构图
2.编写DetectFaceDemo.java,代码如下:
[java] view plaincopy
package com.njupt.zhb.test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;
//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
public class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误
/*
* Detected 0 faces Writing faceDetection.png libpng warning: Image
* width is zero in IHDR libpng warning: Image height is zero in IHDR
* libpng error: Invalid IHDR data
*/
//因此,我们将第一个字符去掉
String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);
Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}
// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}
3.编写测试类:
[java] view plaincopy
package com.njupt.zhb.test;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java246");
new DetectFaceDemo().run();
}
}
//运行结果:
//Hello, OpenCV
//
//Running DetectFaceDemo
///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml
//Detected 8 faces
//Writing faceDetection.png
人脸识别系统使用java的开发
现在主流的还是用的百度,千搜等公司的在线API,就是传图片过去,等接收结果就行,seetaface这个东西太复杂了。
java 人脸识别sdk推荐个好用的?
推荐虹软的,他们的是免费下载的,支持Java,也支持多种平台的开发,接入也比较简单,重点是功能还比较强大。
java怎么实现人脸识别?
应该可以通过java调用别人的人脸识别的接口,主要是利用图像处理的技术,识别关键点