承兑汇票识别
功能介绍
识别承兑汇票识别中的关键字段, 并以json格式返回结构化结果。
约束与限制
- 只支持中英文。
- 只支持识别PNG、JPG、JPEG、BMP、GIF、TIFF、WEBP、PCX、ICO、PSD格式的图片。
- 图像各边的像素大小在15px到8192px之间。
- 图像中识别区域有效占比超过80%,保证所有文字及其边缘包含在图像内。
- 不支持角度旋转的图片识别。
- 支持电子承兑汇票,对于拍照场景、复杂背景支持欠佳。
- 文字识别服务属于公有云服务,线上用户资源共享,如果需要多并发请求,请提前联系我们。
调用方法
请参见如何调用API。
前提条件
在使用承兑汇票识别之前,需要您完成服务申请和认证鉴权,具体操作流程请参见开通服务和认证鉴权章节。
用户首次使用需要先申请开通。服务只需要开通一次即可,后面使用时无需再次申请。如未开通服务,调用服务时会提示ModelArts.4204报错,请在调用服务前先进入控制台开通服务,并注意开通服务区域与调用服务的区域保持一致。
URI
POST /v2/{project_id}/ocr/acceptance-bill
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 用于获取操作API的权限。获取Token接口响应消息头中X-Subject-Token的值即为Token。 |
Enterprise-Project-Id |
否 |
String |
企业项目ID。OCR支持通过企业项目管理(EPS)对不同用户组和用户的资源使用,进行分账。 获取方法:进入“企业项目管理”页面,单击企业项目名称,在企业项目详情页获取Enterprise-Project-Id(企业项目ID)。
企业项目创建步骤请参见用户指南。
说明:
创建企业项目后,在传参时,有以下三类场景。
|
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
image |
否 |
String |
与url二选一。 图像数据,base64编码,要求base64编码后大小不超过10M。 图片最小边不小于15像素,最长边不超过8192像素。支持JPG/PNG/BMP/TIFF格式。 图片Base64编码示例如/9j/4AAQSkZJRgABAg...,带有多余前缀会产生The image format is not supported报错。 |
url |
否 |
String |
与image二选一。 图片的URL路径,目前仅支持华为云上OBS提供的匿名公开授权访问的URL以及公网URL。
说明:
|
响应参数
状态码: 200
参数 |
参数类型 |
描述 |
---|---|---|
result |
AcceptanceBillResult object |
调用成功时表示调用结果。 调用失败时无此字段。 |
参数 |
参数类型 |
描述 |
---|---|---|
issue_date |
String |
出票日期。 |
due_date |
String |
汇票到期日。 |
bill_status |
String |
票据状态。 |
bill_number |
String |
票据号码。 |
issuer_full_name |
String |
出票人全称。 |
issuer_account |
String |
出票人账号。 |
issuer_bank_name |
String |
出票人开户银行。 |
issuer_bank_number |
String |
出票人开户行号。 |
payee_full_name |
String |
收款人全称。 |
payee_account |
String |
收款人账号。 |
payee_bank_name |
String |
收款人开户银行。 |
payee_bank_number |
String |
收款人开户行号。 |
issuance_guarantor_name |
String |
出票保证人名称。 |
issuance_guarantor_address |
String |
出票保证人地址。 |
issuance_guarantor_account |
String |
出票保证人账号。 |
issuance_guarantee_date |
String |
出票保证日期。 |
issuance_guarantor_bank_number |
String |
出票保证人开户行行号。 |
issuance_guarantor_bank_name |
String |
出票保证人开户行名称。 |
amount_in_words |
String |
大写票据金额。 |
amount_in_figures |
String |
小写票据金额。 |
acceptor_full_name |
String |
承兑人全称。 |
acceptor_account |
String |
承兑人账号。 |
acceptor_bank_number |
String |
承兑人开户行行号。 |
acceptor_bank_name |
String |
承兑人开户行名称。 |
contract_number |
String |
交易合同号。 |
assignability |
String |
能否转让。 |
issuer_commitment |
String |
出票人承诺。 |
acceptor_commitment |
String |
承兑人承诺。 |
acceptance_date |
String |
承兑日期。 |
acceptance_guarantor_name |
String |
承兑保证人名称。 |
acceptance_guarantor_address |
String |
承兑保证人地址。 |
acceptance_guarantor_account |
String |
承兑保证人账号。 |
acceptance_guarantee_date |
String |
承兑保证日期。 |
acceptance_guarantor_bank_number |
String |
承兑保证人开户行行号。 |
acceptance_guarantor_bank_name |
String |
承兑保证人开户行名称。 |
issuer_rating_entity |
String |
出票人评级主体。 |
issuer_credit_rating |
String |
出票人信用等级。 |
issuer_rating_due_date |
String |
出票人评级到期日。 |
acceptor_rating_entity |
String |
承兑人评级主体。 |
acceptor_credit_rating |
String |
承兑人信用等级。 |
acceptor_rating_due_date |
String |
承兑人评级到期日。 |
bill_package_number |
String |
票据包号。 |
remarks |
String |
备注。 |
confidence |
Object |
各个字段的置信度。 |
状态码: 400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
调用失败时的错误码,具体请参见错误码。 调用成功时不返回此字段。 |
error_msg |
String |
调用失败时的错误信息。 调用成功时无此字段。 |
请求示例
- 传入承兑汇票图片的base64编码进行文字识别
POST https://{endpoint}/v2/{project_id}/ocr/acceptance-bill Request Header: Content-Type: application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { "image" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." }
- 传入承兑汇票图片的url进行文字识别
POST https://{endpoint}/v2/{project_id}/ocr/acceptance-bill Request Header: Content-Type: application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { "url" : "https://BucketName.obs.myhuaweicloud.com/ObjectName" }
响应示例
状态码: 200
成功响应示例
{ "result" : { "issue_date" : "20xx-07-10", "bill_status" : "背书待签收", "due_date" : "20xx-01-10", "bill_number" : "130212XXX", "issuer_account" : "811180XXX", "payee_account" : "793201XXX", "issuer_full_name" : "XX集团有限公司", "issuer_bank_name" : "XX银行股份有限公司XX支行", "issuer_bank_number" : "302121XXX", "payee_full_name" : "XX有限公司", "payee_bank_name" : "XX银行股份有限公司XX分行", "payee_bank_number" : "303124XXX", "amount_in_figures" : "¥XXX", "amount_in_words" : "XXX元整", "acceptor_bank_name" : "XX银行XX分行", "acceptor_full_name" : "XX银行XX分行", "acceptor_bank_number" : "302121XXX", "issuer_commitment" : "本汇票请予以承兑,到期无条件付款", "acceptor_commitment" : "本汇票已经承兑,到期无条件付款", "assignability" : "可再转让", "acceptance_date" : "20xx-07-10", "issuance_guarantor_name" : "xx", "issuance_guarantor_address" : "xx", "issuance_guarantor_account" : "xx", "issuance_guarantee_date" : "xx", "issuance_guarantor_bank_number" : "xx", "issuance_guarantor_bank_name" : "xx", "acceptor_account" : "xx", "contract_number" : "xx", "acceptance_guarantor_name" : "xx", "acceptance_guarantor_address" : "xx", "acceptance_guarantor_account" : "xx", "acceptance_guarantee_date" : "xx", "acceptance_guarantor_bank_number" : "xx", "acceptance_guarantor_bank_name" : "xx", "issuer_rating_entity" : "xx", "issuer_credit_rating" : "xx", "issuer_rating_due_date" : "xx", "acceptor_rating_entity" : "xx", "acceptor_credit_rating" : "xx", "acceptor_rating_due_date" : "xx", "remarks" : "xxx", "bill_package_number" : "xx", "confidence" : { "issue_date" : 0.9998, "bill_status" : 0.9997, "due_date" : 0.9999, "bill_number" : 1.0, "issuer_account" : 1.0, "payee_account" : 1.0, "issuer_full_name" : 1.0, "issuer_bank_name" : 0.9999, "issuer_bank_number" : 0.999, "payee_full_name" : 1.0, "payee_bank_name" : 0.9999, "payee_bank_number" : 0.9999, "amount_in_figures" : 0.9999, "amount_in_words" : 0.9998, "acceptor_account" : 0.0, "acceptor_bank_name" : 0.9997, "acceptor_full_name" : 0.9999, "acceptor_bank_number" : 0.9998, "issuer_commitment" : 0.9998, "acceptor_commitment" : 1.0, "assignability" : 1.0, "acceptance_date" : 1.0, "issuance_guarantor_name" : 0.0, "issuance_guarantor_address" : 0.0, "issuance_guarantor_account" : 0.0, "issuance_guarantee_date" : 0.0, "issuance_guarantor_bank_number" : 0.0, "issuance_guarantor_bank_name" : 0.0, "contract_number" : 0.0, "acceptance_guarantor_name" : 0.0, "acceptance_guarantor_address" : 0.0, "acceptance_guarantor_account" : 0.0, "acceptance_guarantee_date" : 0.0, "acceptance_guarantor_bank_number" : 0.0, "acceptance_guarantor_bank_name" : 0.0, "issuer_rating_entity" : 0.0, "issuer_credit_rating" : 0.0, "issuer_rating_due_date" : 0.0, "acceptor_rating_entity" : 0.0, "acceptor_credit_rating" : 0.0, "acceptor_rating_due_date" : 0.0, "remarks" : 0.0, "bill_package_number" : 0.0 } } }
状态码: 400
失败响应示例
{ "error_code" : "AIS.0103", "error_msg" : "The image size does not meet the requirements." }
SDK代码示例
SDK代码示例如下。
使用SDK前建议将SDK更新至最新版,防止本地旧版SDK无法使用最新的OCR功能。
- 传入承兑汇票图片的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
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 RecognizeAcceptanceBillSolution { 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("<YOUR REGION>")) .build(); RecognizeAcceptanceBillRequest request = new RecognizeAcceptanceBillRequest(); AcceptanceBillRequestBody body = new AcceptanceBillRequestBody(); body.withImage("/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..."); request.withBody(body); try { RecognizeAcceptanceBillResponse response = client.recognizeAcceptanceBill(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 RecognizeAcceptanceBillSolution { 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("<YOUR REGION>")) .build(); RecognizeAcceptanceBillRequest request = new RecognizeAcceptanceBillRequest(); AcceptanceBillRequestBody body = new AcceptanceBillRequestBody(); body.withUrl("https://BucketName.obs.myhuaweicloud.com/ObjectName"); request.withBody(body); try { RecognizeAcceptanceBillResponse response = client.recognizeAcceptanceBill(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
# 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("<YOUR REGION>")) \ .build() try: request = RecognizeAcceptanceBillRequest() request.body = AcceptanceBillRequestBody( image="/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." ) response = client.recognize_acceptance_bill(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("<YOUR REGION>")) \ .build() try: request = RecognizeAcceptanceBillRequest() request.body = AcceptanceBillRequestBody( url="https://BucketName.obs.myhuaweicloud.com/ObjectName" ) response = client.recognize_acceptance_bill(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
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("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.RecognizeAcceptanceBillRequest{} imageAcceptanceBillRequestBody:= "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." request.Body = &model.AcceptanceBillRequestBody{ Image: &imageAcceptanceBillRequestBody, } response, err := client.RecognizeAcceptanceBill(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("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.RecognizeAcceptanceBillRequest{} urlAcceptanceBillRequestBody:= "https://BucketName.obs.myhuaweicloud.com/ObjectName" request.Body = &model.AcceptanceBillRequestBody{ Url: &urlAcceptanceBillRequestBody, } response, err := client.RecognizeAcceptanceBill(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
成功响应示例 |
400 |
失败响应示例 |
状态码请参见状态码。
错误码
错误码请参见错误码。