本文目錄一覽:
- 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調用別人的人臉識別的接口,主要是利用圖像處理的技術,識別關鍵點
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/284796.html