您的位置:首页 > 编程语言

APIX_身份证图像识别技术(附代码)

2015-11-22 00:38 525 查看
什么是身份证图像识别

身份证识别应用要求文字清晰的大陆二代身份证,文字朝向为正向,图像清晰。同时,身份证号码要求满足国标编码规范,否则不通过验证。API支持支持图片Base64编码和图片URL两种方法,支持的图像格式有jpg、jpeg、gif、png和bmp格式,文件大小在2M以内。

APIX 的身份证识别API,支持身份证正反面识别,其中cmd为idcardfront时,按正面识别,cmd为idcardback时,按反面识别。返回的信息包括姓名、性别、身份证号码、民族、地址,签发机关和有效期等信息。识别率高达92%。

注意事项

传入的身份证图片要求文字方向是正向的,部分手机拍照上传识别的证件图片,多为旋转90度或者180度的身份证照片,导致无法识别。



输出示例



姓名:谢*畅

性别:男

身份证号:330124××××××××9887

民族:汉

地址:广东省汕头市朝阳区光华路××街××号

签发机关:北京市公安局海淀分局

有效期限:2010.05.26-2030.05.26

代码示例,对接详见:http://apix.cn/services/show/35

<span style="font-size:12px;">package com.apix.idcardrecog;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class IDCardRecog {

public static String request(String httpUrl, String httpArg) {
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();

try {
URL url = new URL(httpUrl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");

// 填入apix-key到HTTP header
connection.setRequestProperty("apix-key", "0d758082ac574c4f5***c401ba85");
connection.setDoOutput(true);
connection.getOutputStream().write(httpArg.getBytes("UTF-8"));
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
result = sbf.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

public static void main(String[] args) {
//发送 GET 请求
String httpUrl = "http://a.apix.cn/apixlab/idcardrecog/idcardurl";
String httpArg = "{\"cmd\": \"idcard_front\",\"imgurl\": \"http://images0.cnblogs.com/blog2015/51591/201506/151449465134350.jpg\"}";
String jsonResult = request(httpUrl, httpArg);
System.out.println(jsonResult);
}
}
</span>

Android版代码和Demo下载:http://apix.cn/services/show/35
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息