520
阿里云
名片识别__API介绍_文字识别_人工智能图像类-阿里云
本页面主要介绍服务对应的接口和返回结果中的关键字段的含义,请在阅读本页面之前,了解请求数据格式介绍,了解输入输出的通用数据格式。 此外,在本页最后,附上了名片识别服务调用的程序示例,以供参考。
请求接口
云市场接口
- 请求方法: POST
- 请求url: 在云市场搜索
印刷文字识别-名片识别,在API接口中找到调用地址
数加接口
- 请求方法: POST
- 请求url: 打开管理控制台,接口名称选择
ocr_business_card,查看请求地址
请求参数
| 参数名称 | 参数类型 | 描述 | 默认值 |
|---|---|---|---|
| image | string | dataType为50, dataValue是base64编码后的图像数据, | 空字符串 |
POST请求body 示例如下:
{"inputs": [{"image": {"dataType": 50, #50表示image的数据类型为字符串"dataValue": "base64_image_string" #图片以base64编码的string/oss图片链接}}]}
返回结果格式
返回结果格式如下:
{"outputs": [{"outputLabel": "ocr_businesscard","outputMulti": {},"outputValue": {"dataType": 50,"dataValue": "{"name": "张三", #姓名"company": ["阿里巴巴", "阿里巴巴有限公司" ], #公司结果数组,数组可能为空"department": ["市场部" ], #部门结果数组,数组可能为空"title" : [ "经理" ], #职位结果数组,数组可能为空"tel_cell" : ["15234563443"], #手机结果数组,数组可能为空"tel_work": ["057185212345"], #座机结果数组,数组可能为空"addr": ["浙江省杭州市西湖区文一西路969号"], #地址结果数组,数组可能为空"email": [], #邮箱结果数组 ,数组可能为空"request_id" : 20160822_32423dfsa23432f #请求对应的唯一表示"success": true #识别成功与否 true/false}"}}]}
返回结果是json格式,存放在dataValue字段对应的json String(不是json object)中,主要有如下字段:
- name: 姓名, 类型为字符串
- company: 公司, 类型为字符串数组,如果没有该字段,数组为空
- department: 部门, 类型为字符串数组,如果没有该字段,数组为空
- title: 职位, 类型为字符串数组,如果没有该字段,数组为空
- tel_cell: 手机, 类型为字符串数组,如果没有该字段,数组为空
- tel_work: 座机, 类型为字符串数组,如果没有该字段,数组为空
- addr: 地址, 类型为字符串数组,如果没有该字段,数组为空
- email(暂无): 邮箱, 类型为字符串数组,如果没有该字段,数组为空
- request_id: 请求对应的唯一表示, 用户可以保存该字段用以进行问题追溯,类型为字符串
- success: 识别流程是否出现异常, false表示识别失败,true表示识别成功, 类型为布尔型
程序示例
云市场
在云市场搜索印刷文字识别-名片识别,在API接口中找到请求示例
数加平台
import java.io.File;import java.io.FileInputStream;import java.io.IOException;import sun.misc.BASE64Encoder;import org.json.JSONObject;import org.json.JSONArray;import org.json.JSONException;public class BusinessCard {/** 获取参数的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 img_file = "businesscard.jpg";String service_url = "your-service-url";String ak_id = "your access key id";String ak_secret = "your access key secret";// 对图像进行base64编码String img_base64 = "";try {File file = new File(img_file);byte[] content = new byte[(int) file.length()];FileInputStream finputstream = new FileInputStream(file);finputstream.read(content);finputstream.close();img_base64 = (new BASE64Encoder()).encode(content);} catch (IOException e) {e.printStackTrace();return;}// 拼装请求body的json字符串JSONObject request_obj = new JSONObject();try {JSONObject obj = new JSONObject();JSONArray input_array = new JSONArray();obj.put("image", getParam(50, img_base64));JSONObject config_obj = new JSONObject();config_obj.put("is_oss_data", false);obj.put("configure", getParam(50, config_obj.toString()));input_array.put(obj);request_obj.put("inputs", input_array);} catch (JSONException e) {e.printStackTrace();}String body = request_obj.toString();// Sender代码参考// https://help.aliyun.com/document_detail/shujia/OCR/ocr-api/sender.htmlString result = Sender.sendPost(service_url, body, ak_id, ak_secret);System.out.println(result);// 解析请求结果try {JSONObject result_obj = new JSONObject(result);JSONArray output_array = result_obj.getJSONArray("outputs");// 取出结果json字符串String output = output_array.getJSONObject(0).getJSONObject("outputValue").getString("dataValue"); //请注意,dataValue字段对应的是一个字符串,不是json objectJSONObject out = new JSONObject(output);if (out.getBoolean("success")) {// code to get result// 获取姓名, 只有姓名不是数组String name = out.getString("name");// 获取所有公司结果JSONArray company_array = out.getJSONArray("company");// 获取手机号数组JSONArray tel_cell_array = out.getJSONArray("tel_cell");// 请求对应的唯一表示,可以用于事后debug问题JSONArray request_id_array = out.getJSONArray("request_id");StringBuilder companys = new StringBuilder();StringBuilder cells = new StringBuilder();// 所有公司for (int i = 0; i < company_array.length() - 1; ++i) {companys.append(company_array.getString(i) + ",");}companys.append(company_array.getString(company_array.length() - 1));// 所有手机号for (int i = 0; i < tel_cell_array.length() - 1; ++i) {cells.append(tel_cell_array.getString(i) + ",");}cells.append(tel_cell_array.getString(tel_cell_array.length() - 1));System.out.println("name is " + name + ", Companys is "+ companys.toString() + ",Cells is "+ cells.toString());} else {System.out.println("predict error");}} catch (JSONException e) {e.printStackTrace();}}}
最后更新:2016-11-23 16:04:18
上一篇:
英文识别__API介绍_文字识别_人工智能图像类-阿里云
下一篇:
发送请求示例代码__API介绍_文字识别_人工智能图像类-阿里云
管理索引__数据库开发_用户指南(RDBMS)_数据管理-阿里云
数据推送__性能篇_最佳实践_开放搜索-阿里云
报错信息汇总__常见问题_短信服务-阿里云
编码格式设置__脚本开发_Lite用户使用手册_性能测试-阿里云
开始使用阿里云MNS__快速入门_消息服务-阿里云
修改本机系统Hosts文件来测试Web应用防火墙__常见问题_常见问题_Web 应用防火墙-阿里云
ECS Linux 服务器如何配置网站以及绑定域名__服务与应用_Linux操作运维问题_云服务器 ECS-阿里云
云服务器 ECS Linux SSH 启用 UseDNS 导致连接速度变慢__远程登录 (SSH)_Linux操作运维问题_云服务器 ECS-阿里云
发送事务消息__Java SDK_TCP 接入(专业)_消息队列 MQ-阿里云
美食团购_阿里云帮助中心-阿里云,领先的云计算服务提供商
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云