开发者社区> 问答> 正文

人工智能图像类快速入门方法是什么?



前言


欢迎使用OCR服务,这里主要为您介绍如何使用OCR的各种服务,如何快速找到需要的帮助信息。下文主要通过身份证识别服务的例子来介绍各个流程。



参考示例 — 身份证识别



云市场调用



购买服务


  1. 开通API网关https://www.aliyun.com/product/apigateway

  2. 在身份证服务https://market.aliyun.com/products/57124001/cmapi010401.html 页面购买服务


授权API


  1. 进入API网关 管理控制台,点击左侧调用API—> 应用管理,创建新应用。

  2. 应用创建后,点击应用名称,查看应用ID

  3. 点击左侧已购买API,在对应的API一行中选择查看API,点击更多,授权,输入步骤2获取的应用ID,进行授权即可。


API调用


API的具体调用方式见身份证服务 产品页面
具体的示例代码见产品页面的请求示例代码,通过 此页面查看APPCODE, 请阅读 数据格式说明了解印刷文字识别服务的输入输出格式,阅读 API介绍-身份证了解身份证服务具体的输入输出格式。
示例如下:<divre style='background: rgb(246, 246, 246); font: 12px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin: 0px 0px 16px; padding: 10px; outline: 0px; border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; overflow: auto; word-spacing: 0px; white-space: pre-wrap; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' prettyprinted?="" linenums="">
  1. {
  2.     "inputs": [
  3.     {
  4.         "image": {
  5.             "dataType": 50,                         #50表示image的数据类型为字符串
  6.             "dataValue": "base64_image_string"      #图片以base64编码的string
  7.         },
  8.         "configure": {
  9.             "dataType": 50,
  10.             "dataValue": "\"{
  11.                 \"side\": \"face\",                    #身份证正反面类型: face/back
  12.             }\""
  13.         }
  14.     }]
  15. }

上面列出的是识别身份证正面图像的输入格式,主要是传输了图像数据和配置字符串,其中图像是经过base64编码后的数据,配置字符串主要传递了一个参数,表示当前图像为身份证正面图像,进行正面识别。
返回结果示例如下:<divre style='background: rgb(246, 246, 246); font: 12px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin: 0px 0px 16px; padding: 10px; outline: 0px; border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; overflow: auto; word-spacing: 0px; white-space: pre-wrap; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' prettyprinted?="" linenums="">
  1. {
  2.     "outputs": [
  3.     {
  4.         "outputLabel": "ocr_id",
  5.         "outputMulti": {},
  6.         "outputValue": {
  7.             "dataType": 50,
  8.             "dataValue": "{
  9.                 \"address\"    : \"浙江省杭州市余杭区文一西路969号\",   #地址信息
  10.                 \"config_str\" : \"{\"side\":\"face\"}\",                #配置信息,同输入configure
  11.                 \"name\" : \"张三\",                                  #姓名
  12.                 \"num\" : \"1234567890\",                             #身份证号
  13.                 \"success\" : true                                  #识别结果,true表示成功,false表示失败
  14.             }"
  15.         }
  16.     }]
  17. }

通过outpus[0][“outputValue”][“dataValue”]即可索引到输出结果,对应的字段含义具体可以参见 API介绍-身份证

数加服务调用



开通服务


开通OCR服务,请参考页面 https://data.aliyun.com/product/ocr

了解服务调用方式


  • 参见数加API使用文档 了解数加API使用方法,具体包括以下要点:了解API校验方法
  • 了解API请求参数和请求方法
  • 了解发送请求所需的加密方法,参考示例代码或者原理实现对应的加密函数
  • 获取属于用户自己的Access Key ID和Access Key Secret

服务API地址 : 不同服务的地址可以参见API介绍中各个服务API的说明,依其中方法获取。
用户身份信息: 用户信息包括Access Key ID和Access Key Secret。用户可以访问 阿里云AK管理平台来查看。
了解识别服务的输入输出格式: 具体可以参见 数据格式说明。 身份证识别服务所需字段具体可以参见 API介绍-身份证
base64编码:所需识别身份证图片,需要经过base64编码后进行传输。

身份证服务调用示例


首先,登陆 阿里云AK管理平台获取Access Key ID和Access Key Secret, 阅读API介绍,获取服务对应的url。
其次, 参考 数加API使用文档实现发送Post请求函数sendPost(url, body, ak_id, ak_secret), 也可参考API中 发送请求示例代码
此后, 通过 数据格式说明了解输入输出格式,阅读 API介绍-身份证获取身份证识别的url,以及身份证识别服务所接受的json字段参数, 示例如下:<divre style='background: rgb(246, 246, 246); font: 12px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin: 0px 0px 16px; padding: 10px; outline: 0px; border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; overflow: auto; word-spacing: 0px; white-space: pre-wrap; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' prettyprinted?="" linenums="">
  1. {
  2.     "inputs": [
  3.     {
  4.         "image": {
  5.             "dataType": 50,                         #50表示image的数据类型为字符串
  6.             "dataValue": "base64_image_string"      #图片以base64编码的string
  7.         },
  8.         "configure": {
  9.             "dataType": 50,
  10.             "dataValue": "\"{
  11.                 \"side\": \"face\",                    #身份证正反面类型: face/back
  12.             }\""
  13.         }
  14.     }]
  15. }

上面列出的是识别身份证正面图像的输入格式,可以发现,主要是传输了图像数据和配置字符串,其中图像是经过base64编码后的数据,配置字符串主要传递了一个参数,表示当前图像为身份证正面图像,进行正面识别。
最后,调用sendPost函数,传入url, body,ak_id,ak_secret,即可得到返回结果,如下:<divre style='background: rgb(246, 246, 246); font: 12px/1.6 "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; margin: 0px 0px 16px; padding: 10px; outline: 0px; border-radius: 3px; border: 1px solid rgb(221, 221, 221); color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; overflow: auto; word-spacing: 0px; white-space: pre-wrap; word-wrap: break-word; box-sizing: border-box; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;' prettyprinted?="" linenums="">
  1. {
  2.     "outputs": [
  3.     {
  4.         "outputLabel": "ocr_id",
  5.         "outputMulti": {},
  6.         "outputValue": {
  7.             "dataType": 50,
  8.             "dataValue": "{
  9.                 \"address\"    : \"浙江省杭州市余杭区文一西路969号\",   #地址信息
  10.                 \"config_str\" : \"{\"side\":\"face\"}\",                #配置信息,同输入configure
  11.                 \"name\" : \"张三\",                                  #姓名
  12.                 \"num\" : \"1234567890\",                             #身份证号
  13.                 \"success\" : true                                  #识别结果,true表示成功,false表示失败
  14.             }"
  15.         }
  16.     }]
  17. }

通过outpus[0][“outputValue”][“dataValue”]即可索引到输出结果,对应的字段含义具体可以参见 API介绍-身份证

展开
收起
nicenelly 2017-10-26 10:40:32 2298 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
【云栖精选6月刊】当AI来敲门,一刊尽览人工智能 立即下载
人工智能的商业化落地 立即下载
人工智能的投资机会 立即下载