275
手机大全
驾驶证识别__API介绍_文字识别_人工智能图像类-阿里云
本页面主要介绍服务对应的接口和返回结果中的关键字段的含义,请在阅读本页面之前,了解请求数据格式介绍,了解输入输出的通用数据格式。 此外,在本页最后,附上了驾驶证识别服务调用的程序示例,以供参考。
请求接口
云市场接口
- 请求方法: POST
- 请求url: 在云市场搜索
印刷文字识别-驾驶证识别
,在API接口
中找到调用地址
数加接口
- 请求方法: POST
- 请求url: 打开管理控制台,接口名称选择
ocr_driver_license
,查看请求地址
请求参数
参数名称 | 参数类型 | 描述 | 默认值 |
---|---|---|---|
image | string | dataType为50, dataValue是base64编码后的图像数据 | 空字符串 |
POST请求body 示例如下:
{
"inputs": [
{
"image": {
"dataType": 50, #50表示image的数据类型为字符串
"dataValue": "base64_image_string" #图片以base64编码的string
}
}]
}
返回结果格式
返回结果格式如下:
{
"outputs": [
{
"outputLabel": "ocr_driver_license",
"outputMulti": {},
"outputValue": {
"dataType": 50,
"dataValue": "{
"config_str": "", #配置字符串信息
"name": "张三三", #姓名字符串,识别不出来时,可能为"NoResult"/"InvalidInput"
"num": "360502xxxx03071357", #驾驶证号,识别错误时,为"NoResult"/"InvalidInput"
"vehicle_type":"C1", #驾驶证准驾车型
"start_date": "2010xxxx", #驾驶证有效期开始时间
"end_date": "6", #驾驶证有效期时长
"success": true #识别成功与否 true/false
}"
}
}]
}
每一个请求返回的结果都是一个json字符串,由dataValue关键词可以索引到,主要有7个字段:
- config_str: 表示发送请求时候的配置字符串,为json字符串格式,表示输入时候的配置参数, 类型为字符串
- name: 识别的驾驶证姓名, 类型为字符串
- num: 识别的身份证号码, 类型为字符串
- vehicle_type: 准驾车型, 类型为字符串
- start_date: 驾驶证有效期开始时间, 类型为字符串
- end_date: 驾驶证有效期截止时间/有效时长,具体由驾驶证内容决定, 类型为字符串
- success: 识别流程是否出现异常, false表示识别失败,true表示识别成功, 类型为布尔型
程序示例
云市场
在云市场搜索印刷文字识别-驾驶证识别
,在API接口
中找到请求示例
数加平台
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
public class Driver {
/*
* 获取参数的json对象
*/
public static JSONObject getParam(int type, JSONObject dataValue) {
JSONObject obj = new JSONObject();
try {
obj.put("dataType", type);
obj.put("dataValue", dataValue);
} catch (JSONException e) {
e.printStackTrace();
}
return obj;
}
/*
* 获取参数的json对象
*/
public static JSONObject getParam(int type, String dataValue) {
JSONObject obj = new JSONObject();
try {
obj.put("dataType", type);
obj.put("dataValue", dataValue);
} catch (JSONException e) {
e.printStackTrace();
}
return obj;
}
public static void main(String[] args) {
String imgFile = "driver.jpg";
String serviceURL = "your-service-url";
String akID = "your access key id";
String akSecret = "your access key secret";
// 对图像进行base64编码
String imgBase64 = "";
try {
File file = new File(imgFile);
byte[] content = new byte[(int) file.length()];
FileInputStream finputstream = new FileInputStream(file);
finputstream.read(content);
finputstream.close();
imgBase64 = new String(Base64.encodeBase64(content));
} catch (IOException e) {
e.printStackTrace();
return;
}
// 拼装请求body的json字符串
JSONObject requestObj = new JSONObject();
try {
JSONObject obj = new JSONObject();
JSONArray inputArray = new JSONArray();
obj.put("image", getParam(50, imgBase64));
inputArray.put(obj);
requestObj.put("inputs", inputArray);
} catch (JSONException e) {
e.printStackTrace();
}
String body = requestObj.toString();
//Sender代码参考 https://help.aliyun.com/document_detail/shujia/OCR/ocr-api/sender.html
String result = Sender.sendPost(serviceURL, body, akID, akSecret);
System.out.println(result);
// 解析请求结果
try {
JSONObject resultObj = new JSONObject(result);
JSONArray outputArray = resultObj.getJSONArray("outputs");
String output = outputArray.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); // 取出结果json字符串
JSONObject out = new JSONObject(output);
if (out.getBoolean("success")) {
String type = out.getString("vehicle_type"); // 获取类型
String name = out.getString("name"); // 获取名字
String num = out.getString("num"); // 获取身份证号
String start = out.getString("start_date"); // 获取起始日期
String end = out.getString("end_date"); // 获取有效时长
System.out.printf(" name : %s n num : %sn type : %sn start : %sn end : %sn", name, num, type,
start, end);
} else {
System.out.println("predict error");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
最后更新:2016-11-23 16:04:08
上一篇:
身份证识别__API介绍_文字识别_人工智能图像类-阿里云
下一篇:
行驶证识别__API介绍_文字识别_人工智能图像类-阿里云
负载均衡按域名和URL转发常见问题__常见问题_负载均衡-阿里云
快速切换API版本__API管理相关接口_API_API 网关-阿里云
作业概述__作业管理_SDK参考手册_数据集成-阿里云
直播实时转写__阿里云ET介绍-阿里云
恢复已保存的SQL窗口__使用SQL窗口_SQL操作_用户指南(RDBMS)_数据管理-阿里云
本地IDC自建数据库同RDS实例实时同步__最佳实践_数据传输-阿里云
公众趋势分析__数加产品概览_数加平台介绍-阿里云
文件存储怎么收费?__常见问题_常见问题_文件存储-阿里云
ListTable__API 概览_API 参考_表格存储-阿里云
实例相关接口__API参考_高性能计算-阿里云
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云