智能分类识别-凯发k8国际娱乐官网入口
功能介绍
检测定位图片上指定要识别的票证(票据、证件或其他文字载体),并以json格式返回识别的结构化结果。
接口以列表形式返回图片上要识别票证的位置坐标、结构化识别的内容以及对应的类别。该接口支持的票证类型请见表1,该接口的使用限制请参见约束与限制,详细使用指导请参见ocr服务使用简介章节。
票证类型 |
|
---|---|
身份证头像面 |
银行卡 |
身份证国徽面 |
道路运输证 |
行驶证k8凯发主页 |
增值税发票(含全电发票) |
行驶证副页 |
增值税普通发票(卷票) |
驾驶证k8凯发主页 |
机动车销售统一发票 |
驾驶证副页 |
出租车发票 |
护照 |
火车票 |
车辆通行费发票 |
定额发票 |
飞机行程单 |
- |
智能分类服务只对识别成功的票证进行计费,识别失败的票证不计费。例如,图片中包含三张票证,有两张识别成功,一张识别失败,此时接口计费两次。
约束与限制
- 只支持识别png、jpg、jpeg、bmp、tiff格式图片。
- 图像各边的像素大小在15px到8000px之间。
- 支持图像中票证任意角度的水平旋转。
调用方法
请参见。
前提条件
在使用之前,需要您完成服务申请和认证鉴权,具体操作流程请参见开通服务和章节。
用户首次使用需要先。服务只需要开通一次即可,后面使用时无需再次申请。如未开通服务,调用服务时会提示modelarts.4204报错,请在调用服务前先进入控制台开通服务,并注意开通服务区域与调用服务的区域保持一致。
uri
post /v2/{project_id}/ocr/auto-classification
参数 |
是否必选 |
说明 |
---|---|---|
endpoint |
是 |
终端节点,即调用api的请求地址。 不同服务不同区域的endpoint不同,您可以从中获取。 例如,ocr服务在“华北-北京四”区域的“endpoint”为“ocr.cn-north-4.myhuaweicloud.com”。 |
project_id |
是 |
项目id,您可以从中获取。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
x-auth-token |
是 |
string |
用户token。 用于获取操作api的权限。响应消息头中x-subject-token的值即为token。 |
content-type |
是 |
string |
发送的实体的mime类型,参数值为“application/json”。 |
enterprise-project-id |
否 |
string |
企业项目id。ocr支持通过企业项目管理(eps)对不同用户组和用户的资源使用,进行分账。 获取方法:进入“”页面,单击企业项目名称,在企业项目详情页获取enterprise-project-id(企业项目id)。
企业项目创建步骤请参见用户指南。 说明:
创建企业项目后,在传参时,有以下三类场景。
|
参数 |
是否必选 |
参数类型 |
说明 |
---|---|---|---|
image |
否 |
string |
该参数与url二选一。 图片的base64编码,要求base64编码后大小不超过10mb。 图片最短边不小于15px,最长边不超过8000px,支持jpeg、jpg、png、bmp、tiff格式。 图片base64编码示例如/9j/4aaqskzjrgabag...,带有多余前缀会产生the image format is not supported报错。 |
url |
否 |
string |
该参数与image二选一。图片的url路径,目前支持:
说明:
|
type_list |
否 |
list |
输入图片中,待识别票证的类型,指定后不出现在type_list参数中的票证不识别。不指定时默认返回所有支持类别票证的识别信息。 当前版本支持的票证类型请参见表5。 |
extended_parameters |
否 |
object |
可指定需要识别票证的传入参数,具体参数可参考各票证api文档。若不指定则默认传入image 。当前版本支持票证类型如下:
传参示例: "extended_parameters" : { "vat_invoice" : { "advanced_mode" : true, "return_text_location" : true } } 说明:
若指定票证参数填写错误会导致该票证识别错误,会提示"ais.0101":"the input parameter is invalid."报错。 |
票证类型 |
参数值 |
---|---|
身份证头像面 |
id_card_portrait_side |
身份证国徽面 |
id_card_emblem_side |
行驶证k8凯发主页 |
vehicle_license_front |
行驶证副页 |
vehicle_license_back |
驾驶证k8凯发主页 |
driver_license_front |
驾驶证副页 |
driver_license_back |
护照 |
china_passport或foreign_passport |
银行卡 |
bankcard |
道路运输证 |
transportation_license |
增值税发票(含全电发票) |
vat_invoice 如果输入数据为全电发票,api除返回vat_invoice外。会同时返回全电发票类型: fully_digitalized_special_electronic:全电专用发票 fully_digitalized_normal_electronic:全电普通发票 |
增值税普通发票(卷票) |
vat_roll_invoice |
机动车销售统一发票 |
mvs_invoice |
出租车发票 |
taxi_invoice |
火车票 |
train_ticket |
定额发票 |
quota_invoice |
车辆通行费发票 |
toll_invoice |
飞机行程单 |
flight_itinerary |
响应参数
根据识别的结果,可能有不同的http响应状态码(status code)。例如,200表示api调用成功,400表示调用失败,详细的状态码和响应参数说明如下。
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
result |
array of autoclassificationresult objects |
识别结果。 调用失败时不返回此字段。 |
参数 |
参数类型 |
描述 |
---|---|---|
status |
status object |
指示各对应票证的识别状态。 |
content |
object |
对应票证具体结构化识别的结果。 |
type |
string |
对应票证的类别。 |
location |
array |
文字块的区域位置信息,列表形式,包含文字区域四个顶点的二维坐标(x,y);坐标原点为图片左上角,x轴沿水平方向,y轴沿竖直方向。 |
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
string |
指示各对应票证的状态码。 |
error_msg |
string |
指示各对应票证的状态信息。 |
状态码: 400
参数 |
参数类型 |
说明 |
---|---|---|
error_code |
string |
调用失败时的错误码,具体请参见。 当出现错误码“modelarts.4204”时,请参考为什么调用api时提示“modelarts.4204”?章节。 调用成功时不返回此字段。 |
error_msg |
string |
调用失败时返回的错误信息。 调用成功时不返回此字段。 |
请求示例
- “endpoint”即调用api的请求地址,不同服务不同区域的“endpoint”不同,具体请参见。
例如,智能分类识别服务部署在“华北-北京四”区域的“endpoint”为“ocr.cn-north-4.myhuaweicloud.com”或“ocr.cn-north-4.myhuaweicloud.cn”,请求url为“https://ocr.cn-north-4.myhuaweicloud.com/v2/{project_id}/ocr/auto-classification”,“project_id”为项目id,获取方法请参见。
- 如何获取token请参见。
- 传入图片的base64编码,进行图片分类和内容识别
post https://{endpoint}/v1.0/ocr/auto-classification request header: content-type: application/json x-auth-token: miinrwyjkozihvcnaqccoiinodccdtqcaqexdtalbglghkgbzqmeagewgguvbgkqhkig... request body: { "image":"/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..." }
- 传入图片的url,进行图片分类和内容识别
post https://{endpoint}/v2/{project_id}/ocr/auto-classification request header: content-type: application/json x-auth-token: miinrwyjkozihvcnaqccoiinodccdtqcaqexdtalbglghkgbzqmeagewgguvbgkqhkig... request body: { "url":"https://bucketname.obs.xxxx.com/objectname" }
响应示例
状态码:200
成功响应示例
{ "result": [ { "status": { "error_code": "ais.0000", "error_msg": "succeeded." }, "type": "quota_invoice", "location": [ [65, 1006], [1388, 1006], [1388, 1863], [65, 1863] ], "content": { "code": "13xxxxxx1301", "number": "40xxxx88", "amount": "¥50.00", "location": "上海", "confidence": { "code": 0.9253, "number": 0.9665, "amount": 0.9848, "location": 0.9847 } } }, { "status": { "error_code": "ais.0000", "error_msg": "succeeded." }, "type": "quota_invoice", "location": [ [621, 605], [1328, 605], [1328, 1094], [621, 1094] ], "content": { "code": "13xxxxxx1301", "number": "40xxxx00", "amount": "¥100.00", "location": "上海", "confidence": { "code": 0.9556, "number": 0.9455, "amount": 0.9917, "location": 0.9347 } } }, { "status": { "error_code": "ais.0104", "error_msg": "the image is not supported or the image quality is poor." }, "type": "quota_invoice", "location": [ [816, 103], [2125, 103], [2125, 978], [816, 978] ], "content": {} } ] }
状态码:400
{ "error_code": "ais.0103", "error_msg": "the image size does not meet the requirements." }
sdk代码示例
sdk代码示例如下。
- 传入图片的base64编码,进行图片分类和内容识别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.icredential; import com.huaweicloud.sdk.core.auth.basiccredentials; import com.huaweicloud.sdk.core.exception.connectionexception; import com.huaweicloud.sdk.core.exception.requesttimeoutexception; import com.huaweicloud.sdk.core.exception.serviceresponseexception; import com.huaweicloud.sdk.ocr.v1.region.ocrregion; import com.huaweicloud.sdk.ocr.v1.*; import com.huaweicloud.sdk.ocr.v1.model.*; import java.util.list; import java.util.arraylist; public class recognizeautoclassificationsolution { public static void main(string[] args) { // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment string ak = system.getenv("cloud_sdk_ak"); string sk = system.getenv("cloud_sdk_sk"); icredential auth = new basiccredentials() .withak(ak) .withsk(sk); ocrclient client = ocrclient.newbuilder() .withcredential(auth) .withregion(ocrregion.valueof("
" )) .build(); recognizeautoclassificationrequest request = new recognizeautoclassificationrequest(); autoclassificationrequestbody body = new autoclassificationrequestbody(); list<string> listbodytypelist = new arraylist<>(); listbodytypelist.add("vat_invoice"); listbodytypelist.add("train_ticket"); listbodytypelist.add("taxi_invoice"); body.withextendedparameters("{\"toll_invoice\":{},\"mvs_invoice\":{},\"taxi_invoice\":{\"return_text_location\":true},\"id_card\":{\"return_verification\":true,\"detect_copy\":true,\"return_text_location\":true,\"detect_reproduce\":true},\"vehicle_license\":{\"return_issuing_authority\":true,\"return_text_location\":true},\"quota_invoice\":{},\"vat_invoice\":{\"advanced_mode\":true,\"return_text_location\":true},\"flight_itinerary\":{},\"transportation_license\":{},\"passport\":{},\"train_ticket\":{\"return_text_location\":true},\"bankcard\":{\"return_text_location\":true},\"driver_license\":{\"return_issuing_authority\":true,\"return_text_location\":true}}"); body.withtypelist(listbodytypelist); body.withimage("/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..."); request.withbody(body); try { recognizeautoclassificationresponse response = client.recognizeautoclassification(request); system.out.println(response.tostring()); } catch (connectionexception e) { e.printstacktrace(); } catch (requesttimeoutexception e) { e.printstacktrace(); } catch (serviceresponseexception e) { e.printstacktrace(); system.out.println(e.gethttpstatuscode()); system.out.println(e.getrequestid()); system.out.println(e.geterrorcode()); system.out.println(e.geterrormsg()); } } } - 传入图片的url,进行图片分类和内容识别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.icredential; import com.huaweicloud.sdk.core.auth.basiccredentials; import com.huaweicloud.sdk.core.exception.connectionexception; import com.huaweicloud.sdk.core.exception.requesttimeoutexception; import com.huaweicloud.sdk.core.exception.serviceresponseexception; import com.huaweicloud.sdk.ocr.v1.region.ocrregion; import com.huaweicloud.sdk.ocr.v1.*; import com.huaweicloud.sdk.ocr.v1.model.*; public class recognizeautoclassificationsolution { public static void main(string[] args) { // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment string ak = system.getenv("cloud_sdk_ak"); string sk = system.getenv("cloud_sdk_sk"); icredential auth = new basiccredentials() .withak(ak) .withsk(sk); ocrclient client = ocrclient.newbuilder() .withcredential(auth) .withregion(ocrregion.valueof("
" )) .build(); recognizeautoclassificationrequest request = new recognizeautoclassificationrequest(); autoclassificationrequestbody body = new autoclassificationrequestbody(); body.withurl("https://bucketname.obs.myhuaweicloud.com/objectname"); request.withbody(body); try { recognizeautoclassificationresponse response = client.recognizeautoclassification(request); system.out.println(response.tostring()); } catch (connectionexception e) { e.printstacktrace(); } catch (requesttimeoutexception e) { e.printstacktrace(); } catch (serviceresponseexception e) { e.printstacktrace(); system.out.println(e.gethttpstatuscode()); system.out.println(e.getrequestid()); system.out.println(e.geterrorcode()); system.out.println(e.geterrormsg()); } } }
- 传入图片的base64编码,进行图片分类和内容识别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import basiccredentials from huaweicloudsdkocr.v1.region.ocr_region import ocrregion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkocr.v1 import * if __name__ == "__main__": # the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment ak = os.getenv("cloud_sdk_ak") sk = os.getenv("cloud_sdk_sk") credentials = basiccredentials(ak, sk) \ client = ocrclient.new_builder() \ .with_credentials(credentials) \ .with_region(ocrregion.value_of("
" )) \ .build() try: request = recognizeautoclassificationrequest() listtypelistbody = [ "vat_invoice", "train_ticket", "taxi_invoice" ] request.body = autoclassificationrequestbody( extended_parameters="{\"toll_invoice\":{},\"mvs_invoice\":{},\"taxi_invoice\":{\"return_text_location\":true},\"id_card\":{\"return_verification\":true,\"detect_copy\":true,\"return_text_location\":true,\"detect_reproduce\":true},\"vehicle_license\":{\"return_issuing_authority\":true,\"return_text_location\":true},\"quota_invoice\":{},\"vat_invoice\":{\"advanced_mode\":true,\"return_text_location\":true},\"flight_itinerary\":{},\"transportation_license\":{},\"passport\":{},\"train_ticket\":{\"return_text_location\":true},\"bankcard\":{\"return_text_location\":true},\"driver_license\":{\"return_issuing_authority\":true,\"return_text_location\":true}}", type_list=listtypelistbody, image="/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..." ) response = client.recognize_auto_classification(request) print(response) except exceptions.clientrequestexception as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) - 传入图片的url,进行图片分类和内容识别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
# coding: utf-8 from huaweicloudsdkcore.auth.credentials import basiccredentials from huaweicloudsdkocr.v1.region.ocr_region import ocrregion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkocr.v1 import * if __name__ == "__main__": # the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment ak = os.getenv("cloud_sdk_ak") sk = os.getenv("cloud_sdk_sk") credentials = basiccredentials(ak, sk) \ client = ocrclient.new_builder() \ .with_credentials(credentials) \ .with_region(ocrregion.value_of("
" )) \ .build() try: request = recognizeautoclassificationrequest() request.body = autoclassificationrequestbody( url="https://bucketname.obs.myhuaweicloud.com/objectname" ) response = client.recognize_auto_classification(request) print(response) except exceptions.clientrequestexception as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 传入图片的base64编码,进行图片分类和内容识别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" ocr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/region" ) func main() { // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment ak := os.getenv("cloud_sdk_ak") sk := os.getenv("cloud_sdk_sk") auth := basic.newcredentialsbuilder(). withak(ak). withsk(sk). build() client := ocr.newocrclient( ocr.ocrclientbuilder(). withregion(region.valueof("
" )). withcredential(auth). build()) request := &model.recognizeautoclassificationrequest{} var listtypelistbody = []string{ "vat_invoice", "train_ticket", "taxi_invoice", } var extendedparametersautoclassificationrequestbody interface{} = "{\"toll_invoice\":{},\"mvs_invoice\":{},\"taxi_invoice\":{\"return_text_location\":true},\"id_card\":{\"return_verification\":true,\"detect_copy\":true,\"return_text_location\":true,\"detect_reproduce\":true},\"vehicle_license\":{\"return_issuing_authority\":true,\"return_text_location\":true},\"quota_invoice\":{},\"vat_invoice\":{\"advanced_mode\":true,\"return_text_location\":true},\"flight_itinerary\":{},\"transportation_license\":{},\"passport\":{},\"train_ticket\":{\"return_text_location\":true},\"bankcard\":{\"return_text_location\":true},\"driver_license\":{\"return_issuing_authority\":true,\"return_text_location\":true}}" imageautoclassificationrequestbody:= "/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..." request.body = &model.autoclassificationrequestbody{ extendedparameters: &extendedparametersautoclassificationrequestbody, typelist: &listtypelistbody, image: &imageautoclassificationrequestbody, } response, err := client.recognizeautoclassification(request) if err == nil { fmt.printf("% v\n", response) } else { fmt.println(err) } } - 传入图片的url,进行图片分类和内容识别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" ocr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/region" ) func main() { // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment ak := os.getenv("cloud_sdk_ak") sk := os.getenv("cloud_sdk_sk") auth := basic.newcredentialsbuilder(). withak(ak). withsk(sk). build() client := ocr.newocrclient( ocr.ocrclientbuilder(). withregion(region.valueof("
" )). withcredential(auth). build()) request := &model.recognizeautoclassificationrequest{} urlautoclassificationrequestbody:= "https://bucketname.obs.myhuaweicloud.com/objectname" request.body = &model.autoclassificationrequestbody{ url: &urlautoclassificationrequestbody, } response, err := client.recognizeautoclassification(request) if err == nil { fmt.printf("% v\n", response) } else { fmt.println(err) } }
更多编程语言的sdk代码示例,请参见的代码示例页签,可生成自动对应的sdk代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
成功响应样例 |
400 |
失败响应样例 |
状态码请参见。
错误码
错误码请参见。
意见反馈
文档内容是否对您有帮助?
如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨