Api Ocr

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

Optical Character Recognition

API Reference

Issue 02
Date 2019-07-23

HUAWEI TECHNOLOGIES CO., LTD.


Copyright © Huawei Technologies Co., Ltd. 2020. All rights reserved.
No part of this document may be reproduced or transmitted in any form or by any means without prior
written consent of Huawei Technologies Co., Ltd.

Trademarks and Permissions

and other Huawei trademarks are trademarks of Huawei Technologies Co., Ltd.
All other trademarks and trade names mentioned in this document are the property of their respective
holders.

Notice
The purchased products, services and features are stipulated by the contract made between Huawei and
the customer. All or part of the products, services and features described in this document may not be
within the purchase scope or the usage scope. Unless otherwise specified in the contract, all statements,
information, and recommendations in this document are provided "AS IS" without warranties, guarantees
or representations of any kind, either express or implied.

The information in this document is subject to change without notice. Every effort has been made in the
preparation of this document to ensure accuracy of the contents, but all statements, information, and
recommendations in this document do not constitute a warranty of any kind, express or implied.

Huawei Technologies Co., Ltd.


Address: Huawei Industrial Base
Bantian, Longgang
Shenzhen 518129
People's Republic of China

Website: https://www.huawei.com
Email: support@huawei.com

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. i


Optical Character Recognition
API Reference Contents

Contents

1 Before You Start....................................................................................................................... 1


1.1 Overview.................................................................................................................................................................................... 1
1.2 API Calling..................................................................................................................................................................................1
1.3 Endpoints....................................................................................................................................................................................1
1.4 Constraints................................................................................................................................................................................. 2
1.5 Concepts..................................................................................................................................................................................... 2

2 API Overview............................................................................................................................ 4
3 Calling APIs............................................................................................................................... 5
3.1 Applying for a Service............................................................................................................................................................ 5
3.2 Making an API Request......................................................................................................................................................... 5
3.3 Authentication....................................................................................................................................................................... 10
3.4 Response.................................................................................................................................................................................. 11

4 APIs........................................................................................................................................... 13
4.1 Web Image OCR.................................................................................................................................................................... 13
4.2 Passport OCR.......................................................................................................................................................................... 18
4.3 Thailand ID Card OCR......................................................................................................................................................... 24
4.4 Myanmar ID Card OCR....................................................................................................................................................... 30
4.5 Myanmar Driving License OCR........................................................................................................................................ 37

5 Appendix..................................................................................................................................43
5.1 Status Code............................................................................................................................................................................. 43
5.2 Error Code................................................................................................................................................................................ 47
5.3 Obtaining a Project ID.........................................................................................................................................................53
5.4 Obtaining an Account ID....................................................................................................................................................54
5.5 Configuring Access Permissions of OBS........................................................................................................................ 55

A Change History...................................................................................................................... 57

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. ii


Optical Character Recognition
API Reference 1 Before You Start

1 Before You Start

1.1 Overview
Optical Character Recognition (OCR) allows you to detect and recognize printed
characters in images and convert such characters into editable text.
OCR provides services through open Application Programming Interfaces (APIs).
You can obtain the inference result by accessing and calling APIs in real time. It
helps you collect key data automatically and build an intelligent business system,
thereby improving service efficiency.
You can perform related operations based on the API description, syntax,
parameter description, and examples provided in this document. For example, you
can call the API for recognizing characters in general text, cards, or receipts as
instructed. APIs vary depending on regions. For details, see Endpoints. For details
about all operations supported by APIs, see API Overview.
If you plan to access OCR through an API, ensure that you are familiar with OCR
concepts. For details, see the Optical Character Recognition Service Overview.
OCR also provides software development kits (SDKs) for multiple programming
languages. For details about how to use SDKs, see Optical Character Recognition
SDK Reference.

1.2 API Calling


OCR provides Representational State Transfer (REST) APIs, allowing you to call
APIs using HTTPS. For details about API calling, see Calling APIs.
OCR also provides software development kits (SDKs) for multiple programming
languages. For details about how to use SDKs, see Optical Character Recognition
SDK Reference.

1.3 Endpoints
An endpoint is the request address for calling an API. Endpoints vary depending on
services and regions. For the endpoints of all services, see Regions and Endpoints.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 1


Optical Character Recognition
API Reference 1 Before You Start

Table 1-1 lists the endpoints of OCR. Select a desired one based on the service
requirements.

Table 1-1 OCR endpoints


Regio Endpoi Endpoint Service
n nt
Region

AP- ap- ocr.ap- Passport OCR, Myanmar ID Card OCR,


Hong southe southeast-1.myhuaw and Myanmar Driving License OCR
Kong ast-1 eicloud.com

AP- ap- ocr.ap- Thailand ID Card OCR, Passport OCR,


Bang southe southeast-2.myhuaw and Web Image OCR
kok ast-2 eicloud.com

1.4 Constraints
For details, see the API description and Constraints in the Optical Character
Recognition Service Overview.

1.5 Concepts
● Account
An account is created upon successful registration with HUAWEI CLOUD. The
account has full access permissions for all of its cloud services and resources.
It can be used to reset user passwords and grant user permissions. The
account is a payment entity. For security purposes, do not directly use the
account to perform routine management but create IAM users and grant
them permissions for routine management.
● User
A user is created in IAM using an account to use cloud services. Each user has
its own identity credentials (password and access keys).
An IAM user can view the account ID and user ID on the My Credentials
page of the console. The account name, username, and password will be
required for API authentication.
● Region
Regions are divided based on geographical location and network latency.
Public services, such as Elastic Cloud Server (ECS), Elastic Volume Service
(EVS), Object Storage Service (OBS), Virtual Private Cloud (VPC), Elastic IP
(EIP), and Image Management Service (IMS), are shared within the same
region. Regions are classified as universal regions and dedicated regions. A
universal region provides universal cloud services for common tenants. A
dedicated region provides specific services for specific tenants.
● AZ
An AZ contains one or more physical data centers. It has independent cooling,
fire extinguishing, moisture-proof, and electricity facilities. Within an AZ,

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 2


Optical Character Recognition
API Reference 1 Before You Start

computing, network, storage, and other resources are logically divided into
multiple clusters. AZs within a region are interconnected using high-speed
optical fibers to allow you to build cross-AZ high-availability systems.
● Project
Projects group and isolate resources (including compute, storage, and network
resources) across physical regions. A default project is provided for each
HUAWEI CLOUD region, and subprojects can be created under each default
project. Users can be granted permissions to access all resources in a specific
project. For more refined access control, create subprojects under a project
and purchase resources in the subprojects. Users can then be assigned
permissions to access only specific resources in the subprojects.

Figure 1-1 Project isolation model

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 3


Optical Character Recognition
API Reference 2 API Overview

2 API Overview

You can perform the operations described in Table 2-1 with OCR APIs.

Table 2-1 API description


API Description Deployment
Region

Passport Passport OCR recognizes the text on the first AP-Hong


OCR page of a passport and returns the structured Kong (ap-
information in JSON format. southeast-1
)
AP-Bangkok
(ap-
southeast-2
)

Web Image Web Image OCR recognizes characters in a web AP-Hong


OCR image and returns the structured result in JSON Kong (ap-
format. southeast-1
)

Thailand ID Thailand ID Card OCR recognizes the text on a AP-Bangkok


Card OCR Thailand-issued national registration card. (ap-
southeast-2
)

Myanmar ID Myanmar ID Card OCR recognizes the text on a AP-Hong


Card OCR Myanmar-issued national registration card. Kong (ap-
southeast-1
)

Myanmar Myanmar Driving License OCR recognizes AP-Hong


Driving characters on a Myanmar-issued driver's license Kong (ap-
License OCR and returns the structured result in JSON format. southeast-1
)

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 4


Optical Character Recognition
API Reference 3 Calling APIs

3 Calling APIs

3.1 Applying for a Service


Before using OCR, you must apply for it. The following is the procedure for
applying for OCR.

NOTE

● Before applying for OCR, you must apply for the HUAWEI CLOUD account.
● Before using OCR for the first time, subscribe to it. You only need to subscribe to OCR
once.
● When using OCR for the first time, you need to configure the OBS access permission.
You only need to configure them once. For details, see Configuring Access Permissions
of OBS.

1. Go to the OCR homepage and click Try Now to go to the OCR console. An
account is required for logging in to the OCR console.
2. Select a region where OCR is deployed.
3. In the service list on the left, click the service to be used and click Subscribe.
4. After the service is enabled, it is displayed on the page.

3.2 Making an API Request


This section describes the structure of a REST API, and uses the IAM API for
obtaining a user token as an example to demonstrate how to call an API. The
obtained token can then be used to authenticate the calling of other APIs.

Request URI
A request URI is in the following format:

{URI-scheme} :// {endpoint} / {resource-path} ? {query-string}

Although a request URI is included in the request header, most programming


languages and frameworks require transmitting the request URI separately.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 5


Optical Character Recognition
API Reference 3 Calling APIs

Table 3-1 URI parameter description


Parameter Description

URI-scheme Protocol used to transmit requests. All APIs use HTTPS.

endpoint Domain name or IP address of the server bearing the REST


service. The endpoint varies between services in different
regions. It can be obtained from Regions and Endpoints.

resource-path Access path of an API for performing a specified operation.


Obtain the path from the URI of an API. For example, the
resource-path of the API used to obtain a user token is /v3/
auth/tokens.

query-string Query parameter, which is optional. Ensure that a question


mark (?) is included before each query parameter that is in the
format of "Parameter name=Parameter value". For example,
limit=10 indicates that a maximum of 10 data records will be
displayed.

For example, to obtain an IAM token in the AP-Hong Kong region, obtain the
endpoint of IAM (iam.ap-southeast-1.myhuaweicloud.com) for this region and
the resource-path (/v3/auth/tokens) in the URI of the API used to obtain a user
token. Then, construct the URI as follows:
https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens

Figure 3-1 Example URI

NOTE

To simplify the URI display in this document, each API is provided only with a resource-
path and a request method. The URI-scheme of all APIs is HTTPS, and the endpoints of all
APIs in the same region are identical.

Request Methods
The HTTP protocol defines the following request methods that can be used to
send a request to the server:

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 6


Optical Character Recognition
API Reference 3 Calling APIs

Table 3-2 HTTP-defined request methods


Method Description

GET Requests the server to return specified resources.

PUT Requests the server to update specified resources.

POST Requests the server to add resources or perform special


operations.

DELETE Requests the server to delete specified resources, for


example, an object.

HEAD Same as GET except that the server must return only the
response header.

PATCH Requests the server to update partial content of a specified


resource.
If the resource does not exist, a new resource will be
created.

For example, in the case of the API used to obtain a user token, the request
method is POST. The request is as follows:
POST https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens
Content-Type: application/json
X-Auth-Token: ABCDEFJ....

Request Header
You can also add additional header fields to a request, such as the fields required
by a specified URI or HTTP method. For example, to request for the authentication
information, add Content-Type, which specifies the request body type.
Common request header fields are as follows:

Table 3-3 Common request header fields


Field Description Mandatory Example

Content Specifies the MIME Yes application/json


-Type type of the request
body.

Content Specifies the length of This field is 3495


-Length the request body. The mandatory for
unit is byte. POST and PUT
requests, but
must be left
blank for GET
requests.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 7


Optical Character Recognition
API Reference 3 Calling APIs

Field Description Mandatory Example

X- Specifies the project No e9993fc787d94b6c886cba


Project- ID. This field is used to a340f9c0f4
ID obtain the token for
each project.
This field is mandatory
for the request from a
DeC or multi-project
user.

X-Auth- Specifies the user No -


Token token. This field is
mandatory for
token-based
authentication.

X-Sdk- Time when the No 20150907T101459Z


Date request is sent. The This field is
time is in mandatory for
YYYYMMDD'T'HHMM AK/SK-based
SS'Z' format. authentication.
The value is the
current Greenwich
Mean Time (GMT) of
the system.

Authori Specifies signature No SDK-HMAC-SHA256


zation authentication This field is Credential=ZIRRKMTWPT
information. mandatory for QFQI1WKNKB/
The value can be AK/SK-based 20150907//ec2/
obtained from the authentication. sdk_request,
request signing result. SignedHeaders=content-
type;host;x-sdk-date,
Signature=55741b610f3c
9fa3ae40b5a8021ebf7ebc
2a28a603fc62d25cb3bfe6
608e1994

Host Specifies the server No code.test.com


domain name and This field is or
port number of the mandatory for
resource being code.test.com:443
AK/SK-based
requested. The value authentication.
can be obtained from
the URL of a service
API. The value is
hostname[:port]. If the
port number is not
specified, the default
port is used. The
default port number
for https is 443.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 8


Optical Character Recognition
API Reference 3 Calling APIs

NOTE

In addition to supporting token-based authentication, public cloud APIs also support


authentication using access key ID/secret access key (AK/SK). During AK/SK-based
authentication, an SDK is used to sign the request, and the Authorization (signature
information) and X-Sdk-Date (time when the request is sent) header fields are
automatically added to the request.
For more details, see AK/SK-based Authentication.

The API used to obtain a user token does not require authentication. Therefore,
this API only requires adding the Content-Type field. An example of such requests
is as follows:
POST https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens
Content-Type: application/json

Request Body
The body of a request is often sent in a structured format as specified in the
Content-Type header field. The request body transfers content except the request
header.
The request body varies between APIs. Some APIs do not require the request body,
such as the APIs requested using the GET and DELETE methods.
For the API of obtaining a user token, obtain the request parameters and
parameter description in the API request. The following provides an example
request with a body included. Replace username, domainname, ******** (login
password), and xxxxxxxx (project name) with the actual values and obtain the
token specified for the project. For example, if the project name is set to ap-
southeast-1, the obtained token applies to the services in ap-southeast-1. For
details about how to obtain a username, domainname, and project name, see
Obtaining the Username, User ID, Project Name, and Project ID.

NOTE

The scope parameter specifies where a token takes effect. You can set scope to an account
or a project under an account. In the following example, the token takes effect only for the
resources in a specified project. For more information about this API, see Obtaining a User
Token.
POST https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens
Content-Type: application/json

{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "username", //Replace the value with the actual username.
"password": "********", //Replace the value with the actual password.
"domain": {
"name": "domainname" //Replace the value with the actual domain name.
}
}
}

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 9


Optical Character Recognition
API Reference 3 Calling APIs

},
"scope": {
"project": {
"name": "xxxxxxxx" //Replace xxxxxxxx with the actual project name. For example, ap-
southeast-1.
}
}
}
}

If all data required for the API request is available, you can send the request to call
the API through curl, Postman, or coding. In the response to the API used to
obtain a user token, x-subject-token is the desired user token. This token can
then be used to authenticate the calling of other APIs.

3.3 Authentication
Requests for calling an API can be authenticated using either of the following
methods:

● Token-based authentication: Requests are authenticated using a token.


● AK/SK-based authentication: Requests are authenticated by encrypting the
request body using an AK/SK pair.

Token-based Authentication
NOTE

The validity period of a token is 24 hours. When using a token for authentication, cache it
to prevent frequently calling the IAM API used to obtain a user token.

A token specifies temporary permissions in a computer system. During API


authentication using a token, the token is added to requests to get permissions for
calling the API.

In Making an API Request, the process of calling the API used to obtain a user
token is described. After a token is obtained, the X-Auth-Token header field must
be added to requests to specify the token when calling other APIs. For example, if
the token is ABCDEFJ...., X-Auth-Token: ABCDEFJ.... can be added to a request as
follows:

GET https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/projects
Content-Type: application/json
X-Auth-Token: ABCDEFJ....

AK/SK-based Authentication
NOTE

AK/SK-based authentication supports API requests with a body not larger than 12 MB. For
API requests with a larger body, token-based authentication is recommended.

In AK/SK-based authentication, AK/SK is used to sign requests and the signature is


then added to the requests for authentication.

● AK: access key ID, which is a unique identifier used in conjunction with a
secret access key to sign requests cryptographically.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 10


Optical Character Recognition
API Reference 3 Calling APIs

● SK: secret access key used in conjunction with an AK to sign requests


cryptographically. It identifies a request sender and prevents the request from
being modified.

In AK/SK-based authentication, you can use an AK/SK to sign a request based on


the signature algorithm or use a dedicated signature SDK to sign a request. For
details about how to sign requests and use the signing SDK, see the API Request
Signing Guide.
If no AK/SK has been generated, access the My Credentials page, and choose
Access Keys > Create Access Key to obtain the access keys.

NOTICE

The signing SDK is only used for signing requests and is different from the SDKs
provided by services.
For details about how to obtain the AK/SK, see Obtaining the AK/SK.

3.4 Response
Status Code
After sending a request, you will receive a response, including a status code,
response header, and response body.

A status code is a group of digits, ranging from 1xx to 5xx. It indicates the status
of a request. For more information, see Status Code.

For example, if status code 201 is returned for calling the API used to obtain a
user token, the request is successful.

Response Header
Similar to a request, a response also has a header, for example, Content-Type. For
more information, see Table 3-4.

Table 3-4 Response Header

Field Description

Content-Length Length of the response body. The unit is byte.

Date Time when a request response is returned

Content-Type MIME type of the response body

Figure 3-2 shows the response header fields for the API used to obtain a user
token. The x-subject-token header field is the desired user token. This token can
then be used to authenticate the calling of other APIs.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 11


Optical Character Recognition
API Reference 3 Calling APIs

Figure 3-2 Header fields of the response to the request for obtaining a user token

Response Body
The body of a response is often returned in structured format as specified in the
Content-Type header field. The response body transfers content except the
response header.
The following is part of the response body for the API used to obtain a user
token.
{
"token": {
"expires_at": "2019-02-13T06:52:13.855000Z",
"methods": [
"password"
],
"catalog": [
{
"endpoints": [
{
"region_id": "aaa"//The region ID aaa is used as an example.
......

If an error occurs during API calling, an error code and a message will be
displayed. The following shows an error response body.
{
"error_msg": "The format of message is error",
"error_code": "AS.0001"
}

In the response body, error_code is an error code, and error_msg provides


information about the error.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 12


Optical Character Recognition
API Reference 4 APIs

4 APIs

4.1 Web Image OCR


Function
Web Image OCR recognizes characters in a web image and returns the structured
result in JSON format. For details about the constraints on using this API, see
Constraints. For details about how to use this API, see .

Prerequisites
Before using Web Image OCR, you need to apply for the service and complete
authentication. For details, see Applying for a Service and Authentication.

URL
POST https://{endpoint}/v1.0/ocr/web-image

Table 4-1 Parameter description

Parameter Mandator Description


y

endpoint Yes Domain name or IP address of the server


bearing the REST service endpoint. The endpoint
varies between services in different regions. It
can be obtained from Endpoints.

Request Message
Table 4-2 describes the request parameters of Web Image OCR.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 13


Optical Character Recognition
API Reference 4 APIs

Table 4-2 Request parameters


Parameter Mandator Type Description
y

image No. Set String Base64 character string converted


either this from the image. The size cannot
parameter exceed 10 MB.
or url. The narrow edge contains at least
15 pixels and the wide edge
contains at most 8,192 pixels. The
JPEG, JPG, PNG, BMP, TIFF, GIF,
and WebP formats are supported.

url No. Set String Image URL. Currently, the


either this following URLs are supported:
parameter ● Public network HTTP/HTTPS
or image. URL.
● URL provided by OBS. You need
to be authorized for using OBS
data, including service
authorization, temporary
authorization, and anonymous
public authorization. For
details, see Configuring Access
Permissions of OBS.
NOTE
● The API response time depends on
the image download time. If the
image download takes a long
time, the API call will fail.
● Ensure that the storage service
where the images to be detected
reside is stable and reliable. OBS is
recommended for storing image
data.

detect_direction No Boolean Indicates whether to enable the


function of aligning a tilted image.
The options are as follows:
● true: The tilted image is
aligned.
● false: The tilted image is not
aligned.
An image tilted at any angle can
be aligned. If this parameter is not
specified, the default value false is
used.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 14


Optical Character Recognition
API Reference 4 APIs

Parameter Mandator Type Description


y

extract_type No Array of Structured data extraction


strings parameter list. Currently, only the
contact information and image
width and height are supported.
The input parameter values are
contact_info and image_size,
respectively.
If this parameter is not set or
deleted, the value of this
parameter is not used by default.

Response Message
Table 4-3 describes the response parameters of Web Image OCR.

Table 4-3 Response parameters


Parameter Type Description

result Object Calling result of a successful API call.


This parameter is not included when
the API call fails.

words_block_count Integer Number of detected text blocks.

words_block_list Array of List of text blocks to be recognized.


objects The output sequence is from left to
right and from top to bottom.

words String Recognition result of a text block

location Array of List of location information about a


objects text block, including the coordinates (x,
y) of vertexes of the text block, where
the coordinate origin is the upper-left
vertex of the image. The x-axis is
horizontal, and the y-axis is vertical.

extracted_data Object Extracted structured JSON result. The


key value is the same as that of
extract_type in the request parameter
list. Currently, only contact information
can be extracted, that is, contact_info.
If extract_type is left blank or missing,
no information is extracted.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 15


Optical Character Recognition
API Reference 4 APIs

Parameter Type Description

contact_info Object Extracted contact information,


including the name, phone number,
province, city, and detailed address.
If extract_type does not contain this
parameter, this parameter does not
exist in the response.

image_size Object Width and height of an image.


If extract_type does not contain this
parameter, this parameter does not
exist in the response.

height Integer Image height, which is returned when


image_size is passed.

width Integer Image width, which is returned when


image_size is passed.

name String Name, which is returned when


contact_info is passed.

phone String Contact phone number, which is


returned when contact_info is passed.

province String Province, which is returned when


contact_info is passed.

city String City, which is returned when


contact_info is passed.

district String County or district, which is returned


when contact_info is passed.

detail_address String Detailed address (excluding the


province, city, and county or district),
which is returned when contact_info is
passed.

confidence Float Confidence information of a related


field. The value ranges from 0 to 1.
A higher confidence level indicates a
higher reliability and accuracy of the
corresponding field identified this time.
The confidence is calculated by the
algorithm and is not equal to the
accuracy of the field.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 16


Optical Character Recognition
API Reference 4 APIs

Parameter Type Description

error_code String Error code of a failed API call. For


details, see Error Code.
If the error code ModelArts.4204 is
displayed, refer to Why Is a Message
Stating "ModelArts.4204" Displayed
When the OCR API Is Called for
troubleshooting.
This parameter is not included when
the API is successfully called.

error_msg String Error message of a failed API call.

Example
NOTE

The endpoint is the request URL for calling an API. Endpoints vary according to services and
regions. For details, see Endpoints.
For example, the endpoint of Web Image OCR in the CN South-Guangzhou region is
ocr.cn-south-1.myhuaweicloud.com, so the request URL is https://ocr.cn-
south-1.myhuaweicloud.com/v1.0/ocr/web-image.
● Request example (Method 1: Use a Base64-encoded image.)
POST https://{endpoint}/v1.0/ocr/web-image

Request Header:
Content-Type: application/json,
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...

Request Body:
{
"image":"/9j/4AAQSkZJRgABAgEASABIAAD/..."
}

● Request example (Method 2: Use the URL redirecting to the image file.)
POST https://{endpoint}/v1.0/ocr/web-image

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"url":"https://BucketName.obs.xxxx.com/ObjectName"
}

● Sample code for a Python request (For details about other languages, see the
following sample code or use the OCR SDK.)
# encoding:utf-8

import requests
import base64

url = "https://{endpoint}/v1.0/ocr/web-image"
token = "Actual token value obtained by the user"
headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

imagepath = r'./data/web-image-demo.png'

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 17


Optical Character Recognition
API Reference 4 APIs

with open(imagepath, "rb") as bin_data:


image_data = bin_data.read()
image_base64 = base64.b64encode(image_data).decode("utf-8") # Base64 encoding of images.
payload = {"image": image_base64} # url or image.
response = requests.post(url, headers=headers, json=payload)
print(response.text)
● Response example
{
"result": {
"words_block_count": 2,
"words_block_list": [
{
"words": "words recognized from the image",
"confidence": 0.9950,
"location": [
[13, 476],
[91, 332],
[125, 351],
[48, 494]
]
},
{
"words": "words recognized from the image",
"confidence": 0.9910,
"location": [
[13, 476],
[91, 332],
[125, 351],
[48, 494]
]
}
],
"extracted_data": {}
}
}
● Failed response example
{
"error_code": "AIS.0103",
"error_msg": "The image size does not meet the requirements."
}

Status Code
For details about the status code, see Status Code.

Error Code
For details about the error code, see Error Code.

4.2 Passport OCR


Function
Passport OCR recognizes the text on the first page of a passport and returns the
structured information in JSON format.
Passport OCR can recognize all fields on a Chinese passport. A foreign passport
can be identified by the machine-readable code at the bottom of the passport
with 6 to 7 key fields extracted from the code. For details about the constraints on
using this API, see Constraints. For details about how to use this API, see
Introduction to OCR.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 18


Optical Character Recognition
API Reference 4 APIs

Prerequisites
Before using Passport OCR, you need to apply for the service and complete
authentication. For details, see Applying for a Service and Authentication.

URL
POST https://{endpoint}/v1.0/ocr/passport

Table 4-4 Parameter description


Parameter Mandator Description
y

endpoint Yes Domain name or IP address of the server


bearing the REST service endpoint. The endpoint
varies between services in different regions. It
can be obtained from Endpoints.

Request Message
Table 4-5 describes the request parameters of Passport OCR.

Table 4-5 Request parameters


Parameter Mandator Type Description
y

image No. Set String Base64 character string converted


either this from the image. The size cannot
parameter exceed 10 MB.
or url. The narrow edge contains at least
15 pixels and the wide edge
contains at most 4,096 pixels. The
JPEG, JPG, PNG, BMP, and TIFF
formats are supported.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 19


Optical Character Recognition
API Reference 4 APIs

Parameter Mandator Type Description


y

url No. Set String Image URL. Currently, the


either this following URLs are supported:
parameter ● HTTP/HTTPS URL
or image.
● URL provided by OBS. You need
to be authorized to use OBS
data, including service
authorization, temporary
authorization, and anonymous
public authorization. For
details, see Configuring Access
Permissions of OBS.
NOTE
● The API response time depends on
the image download time. If the
image download takes a long
time, the API call will fail.
● Ensure that the storage service
where the images to be detected
reside is stable and reliable. OBS is
recommended for storing image
data.

country_code No String Country code on the passport. The


recognition mode is determined
based on the country code.
● If this parameter is left blank,
OCR automatically matches the
recognition mode based on the
passport type identified by the
service.
● If you set this parameter to
GENERAL, the passport is
recognized based on the
machine-readable code.
● If this parameter is set to CHN,
all fields in the Chinese
passport are recognized.

Response Message
Table 4-6 describes the response parameters of Passport OCR.

Table 4-6 Response parameters


Parameter Type Description

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 20


Optical Character Recognition
API Reference 4 APIs

result Object Calling result of a successful API call.


This parameter is not included when
the API call fails.

passport_type String Passport type. Possible values are as


follows:
● P: ordinary passport
● W: diplomatic passport
● G: service passport

country_code String Country code

passport_number String Passport ID

nationality String Nationality of the passport holder

surname String Last name

given_name String Given game

sex String Sex.

date_of_birth String Date of birth

date_of_expiry String Date on which the passport expires

date_of_issue String Date of issue

place_of_birth String Place of birth

place_of_issue String Place where the passport is issued

issuing_authority String Authority that issues the passport.


The abbreviation of the issuing
authority of each consulate is not
unified. The abbreviation of Chinese
issuing authority is P.R.China. For
example, if the issuing authority is
P.R.C, the recognition result is
P.R.China.

confidence Object Confidence information of a related


field. The value ranges from 0 to 1.
Confidence of related fields. A higher
confidence indicates a more accurate
result.
The confidence is provided by the
algorithm and is not equal to the
accuracy of the field.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 21


Optical Character Recognition
API Reference 4 APIs

extra_info Object By default, this parameter is left blank.


For a Chinese passport, extra_info
contains Chinese character-described
fields on the passport, such as the
name and place of birth.

error_code String Error code of a failed API call. For


details, see Error Code.
If the error code ModelArts.4204 is
displayed, refer to Why Is a Message
Stating "ModelArts.4204" Displayed
When the OCR API Is Called for
troubleshooting.
This parameter is not included when
the API is successfully called.

error_msg String Error message of a failed API call.


This parameter is not included when
the API is successfully called.

Example
NOTE

The endpoint is the request URL for calling an API. Endpoints vary according to services and
regions. For details, see Endpoints.
For example, the endpoint of Passport OCR in the AP-Hong Kong region is ocr.ap-
southeast-1.myhuaweicloud.com, so the request URL is https://ocr.ap-
southeast-1.myhuaweicloud.com/v1.0/ocr/passport.
● Request example (Method 1: Use a Base64-encoded image.)
POST https://{endpoint}/v1.0/ocr/passport

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA...",
"country_code": "GENERAL"
}
● Request example (Method 2: Use the URL redirecting to the image file.)
POST https://{endpoint}/v1.0/ocr/passport

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"url":"https://BucketName.obs.xxxx.com/ObjectName",
"country_code": "GENERAL"
}
● Sample code for a Python request (For details about other languages, see the
following sample code or use the OCR SDK.)
# encoding:utf-8

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 22


Optical Character Recognition
API Reference 4 APIs

import requests
import base64

url = "https://{endpoint}/v1.0/ocr/passport"
token = "Actual token value obtained by the user"
headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

imagepath = r'./data/passport-demo.png'
with open(imagepath, "rb") as bin_data:
image_data = bin_data.read()
image_base64 = base64.b64encode(image_data).decode("utf-8") # Base64 encoding of images.
payload = {"image": image_base64} # url or image.
response = requests.post(url, headers=headers, json=payload)
print(response.text)
● Response example
– Example 1: Chinese passport
{
"result": {
"passport_type": "P",
"country_code": "CHN",
"passport_number": "ED999XXXX",
"nationality": "CHINESE",
"surname": "ZHANG",
"given_name": "SAN",
"sex": "F",
"date_of_birth": "1990-12-12",
"date_of_expiry": "2020-07-08",
"date_of_issue": "2010-07-09",
"place_of_birth": "HUNAN",
"place_of_issue": "GUANGDONG",
"issuing_authority": "MPS Exit & Entry Administration",
"extra_info": {
"local_language": {
"name": "name recognized from the image",
"sex": "sex recognized from the image",
"place_of_birth": "place of birth recognized from the image",
"place_of_issue": "place of issue recognized from the image",
"issuing_authority": "issuing authority recognized from the image",
"nationality": "nationality recognized from the image",
}
},
"confidence": {
"passport_type": 1.0,
"country_code": 1.0,
"passport_number": 0.9997,
"nationality": 1.0,
"surname": 0.9729,
"given_name": 0.9729,
"sex": 1.0,
"date_of_birth": 0.9998,
"date_of_expiry": 0.9995,
"date_of_issue": 0.9969,
"place_of_birth": 1.0,
"place_of_issue": 1.0,
"issuing_authority": 0.9985
}
}
}
– Example 2: Foreign passport
{
"result": {
"country_code": "ETF",
"surname": "HUZHAO",
"given_name": "ZHAOMIN DESALEGN ",
"passport_number": "EP435XXXX",
"date_of_birth": "1985-09-18",
"sex": "M",
"date_of_expiry": "2022-01-15",

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 23


Optical Character Recognition
API Reference 4 APIs

"machine_code": "P<ETFHUZHAO<< ZHAOMIN <DESALEGN<<<<<<<<<<<<<<<",


"machine_code2": "EP435XXXX7ETF8509185M2201155<<<<<<<<<<<<<<08",
"extra_info": {},
"confidence": {
"country_code": 0.9727,
"surname": 0.9727,
"given_name": 0.9727,
"passport_number": 0.9558,
"date_of_birth": 0.9558,
"sex": 0.9558,
"date_of_expiry": 0.9558
}
}
}

● Failed response example


{
"error_code": "AIS.0103",
"error_msg": "The image size does not meet the requirements."
}

Status Code
For details about the status code, see Status Code.

Error Code
For details about the error code, see Error Code.

4.3 Thailand ID Card OCR


Function
Thailand ID Card OCR recognizes characters on a Thailand-issued national
registration card and returns the structured result in JSON format. For details
about the constraints on using this API, see Constraints For details about how to
use this API, see Introduction to OCR.

Prerequisites
Before using Thailand ID Card OCR, you need to apply for the service and
complete authentication. For details, see Applying for a Service and
Authentication.

URL
POST https://{endpoint}/v1.0/ocr/thailand-id-card

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 24


Optical Character Recognition
API Reference 4 APIs

Table 4-7 Parameter description


Parameter Mandator Description
y

endpoint Yes Domain name or IP address of the server


bearing the REST service endpoint. The endpoint
varies between services in different regions. It
can be obtained from Endpoints.

Request Message
Table 4-8 describes the request parameters of Thailand ID Card OCR.

Table 4-8 Request parameters


Parameter Mandatory Type Description

image No. Set either String Base64 character string converted


this parameter from the image. The size cannot
or url. exceed 10 MB.
The narrow edge contains at least
15 pixels and the wide edge
contains at most 8,192 pixels. The
JPEG, JPG, PNG, BMP, and TIFF
formats are supported.

url No. Set either String Image URL. Currently, the


this parameter following URLs are supported:
or image. ● HTTP/HTTPS URL
● URL provided by OBS. You
need to be authorized to use
OBS data, including service
authorization, temporary
authorization, and anonymous
public authorization. For
details, see Configuring Access
Permissions of OBS.
NOTE
● The API response time depends on
the image download time. If the
image download takes a long
time, the API call will fail.
● Ensure that the storage service
where the images to be detected
reside is stable and reliable. OBS is
recommended for storing image
data.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 25


Optical Character Recognition
API Reference 4 APIs

Parameter Mandatory Type Description

side No String ● front: front of an ID card.


● back: back of an ID card.
If this parameter is left empty or
not included, the system
automatically recognizes whether
the image is the front or back of
an ID card. To ensure accuracy,
you are advised to set this
parameter.

return_portra No Boolean Specifies whether to return the


it_image head portrait. Possible values are
as follows:
● true: The Base64 code of the
head portrait on the ID card is
returned.
● false: The Base64 code of the
head portrait on the ID card is
not returned.
If this parameter is not
transferred, the default value
false is used. That is, the Base64
code of the head portrait on the
ID card is not returned.

return_portra No Boolean Specifies whether to return the


it_location location of the head portrait on
the ID card. Possible values are as
follows:
● true: The location of the head
portrait on the ID card is
returned.
● false: The location of the head
portrait on the ID card is not
returned.

return_idcard No Boolean Specifies whether to return the ID


_type card type. Possible values are as
follows:
● true: The ID card type is
returned, including the original
ID card and the copy of the ID
card.
● false: The ID card type is not
returned.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 26


Optical Character Recognition
API Reference 4 APIs

Response Message
Table 4-9 describes the response parameters of Thailand ID Card OCR.

Table 4-9 Response parameters


Parameter Type Description

result Object Calling result of a successful API call

id_number String ID number

name_th String Thai name

first_name_en String English given name

last_name_en String English surname

date_of_birth_th String Date of birth, in Thai

date_of_birth_en String Date of birth, in English

religion_th String Religion

address_th String Address on the ID card

date_of_issue_th String Date of issue, in Thai

date_of_issue_en String Date of issue, in English

date_of_expiry_th String Date of expiry, in Thai

date_of_expiry_en String Date of expiry, in English

serial_number String Serial number

card_number String ID number on the back of the ID card

laser_number String Laser code

confidence Object Confidence information of a related field.


The value ranges from 0 to 1.
A higher confidence indicates a higher
reliability of the corresponding field
identified this time. In the statistical
sense, a higher confidence indicates a
higher accuracy.
The confidence is provided by the
algorithm and is not equal to the
accuracy of the field.

portrait_image String Base64 code of the head portrait.


This parameter is available only when
return_portrait_image is set to true.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 27


Optical Character Recognition
API Reference 4 APIs

Parameter Type Description

portrait_location Array of Location of the head portrait on the


objects original image.
This parameter is available only when
return_portrait_location is set to true.
The image is displayed in a list. The list
contains the two-dimensional coordinates
(x,y) of the four vertices in the head
portrait area. The origin of the
coordinates is the upper left corner of the
image. The x axis is horizontal, and the y
axis is vertical.

idcard_type String ID card type. Possible values are as


follows:
● normal: original ID card
● copy: copy of the ID card
This parameter is available only when
return_idcard_type is set to true.

error_code String Error code of a failed API call. For details,


see Error Code.
If the error code ModelArts.4204 is
displayed, refer to Why Is a Message
Stating "ModelArts.4204" Displayed
When the OCR API Is Called for
troubleshooting.
This parameter is not included when the
API is successfully called.

error_msg String Error message of a failed API call.


This parameter is not included when the
API is successfully called.

Example
NOTE

The endpoint is the request URL for calling an API. Endpoints vary according to services and
regions. For details, see Endpoints.
For example, the endpoint of Thailand ID Card OCR in the AP-Bangkok region is ocr.ap-
southeast-2.myhuaweicloud.com, so the request URL is https://ocr.ap-
southeast-2.myhuaweicloud.com/v1.0/ocr/thailand-id-card.
● Request example (Method 1: Use a Base64-encoded image.)
POST https://{endpoint}/v1.0/ocr/thailand-id-card

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 28


Optical Character Recognition
API Reference 4 APIs

{
"image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAA...",
"side":"front",
"return_portrait_image":true,
"return_portrait_location ":true,
"return_idcard_type":true
}

● Request example (Method 2: Use the URL redirecting to the image file.)
POST https://{endpoint}/v1.0/ocr/thailand-id-card

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"url":"https://BucketName.obs.xxxx.com/ObjectName"
}

● Sample code for a Python request (For details about other languages, see the
following sample code or use the OCR SDK.)
# encoding:utf-8

import requests
import base64

url = "https://{endpoint}/v1.0/ocr/thailand-id-card"
token = "Actual token value obtained by the user"
headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

imagepath = r'./data/thailand-id-card-demo.png'
with open(imagepath, "rb") as bin_data:
image_data = bin_data.read()
image_base64 = base64.b64encode(image_data).decode("utf-8") # Base64 encoding of images.
payload = {"image": image_base64} # url or image.
response = requests.post(url, headers=headers, json=payload)
print(response.text)

● Successful response example (the front)


{
"result": {
"id_number": "X XXXX XXXXX XX X",
"name_th": "XXX",
"first_name_en": "XX",
"last_name_en": "XX",
"date_of_birth_th": "5 ก.พ. 2493",
"date_of_birth_en": "5 Feb. 1950",
"religion_th": "XX",
"address_th": "XXXXX",
"date_of_issue_th": "XX",
"date_of_issue_en": "4 Mar. 2011",
"date_of_expiry_th": "22 ก.พ. 2561",
"date_of_expiry_en": "22 Feb. 2018",
"serial_number": "XXXX-XX-XXXXX",
"confidence": {
"id_number": 0.9999,
"name_th": 0.9994,
"first_name_en": 0.998,
"last_name_en": 0.9997,
"date_of_birth_th": 0.9996,
"date_of_birth_en": 0.9997,
"religion_th": 0.686,
"address_th": 0.624,
"date_of_issue_th": 1,
"date_of_issue_en": 1,
"date_of_expiry_th": 0.9969,
"date_of_expiry_en": 0.61,
"serial_number": 0.9887
},

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 29


Optical Character Recognition
API Reference 4 APIs

"portrait_image": "/9j/4AA... ",


"portrait_location": [
[576, 237],
[741, 237],
[739, 430],
[574, 431]
],
"idcard_type": "normal"
}
}

● Successful response example (the back)


{
"result": {
"card_number": "XXXX-XXX-XX",
"laser_number": "XXXX-XXXXXXX-XX",
"confidence": {
"id_number": 0.9999,
"laser_number": 0.9994
}
}
}

● Failed response example


{
"error_code": "AIS.0103",
"error_msg": "The image size does not meet the requirements."
}

Status Code
For details about the status code, see Status Code.

Error Code
For details about the error code, see Error Code.

4.4 Myanmar ID Card OCR


Function
Myanmar ID Card OCR recognizes information on Myanmar-issued national
registration cards. For details about the constraints on using this API, see
Constraints. For details about how to use this API, see Introduction to OCR.

Prerequisites
Before using Myanmar ID Card OCR, you need to apply for the service and
complete authentication. For details, see Applying for a Service and
Authentication.

URL
POST https://{endpoint}/v1.0/myanmar-id-card

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 30


Optical Character Recognition
API Reference 4 APIs

Table 4-10 Parameter description


Parameter Mandator Description
y

endpoint Yes Domain name or IP address of the server


bearing the REST service endpoint. The endpoint
varies between services in different regions. It
can be obtained from Endpoints.

Request Message
Table 4-11 describes the request parameters of Myanmar ID Card OCR.

Table 4-11 Request parameters


Parameter Mand Type Description
atory

image No. String Base64 character string converted


Set from the image. The size cannot
either exceed 10 MB.
this The narrow edge contains at least 15
param pixels and the wide edge contains at
eter most 8,000 pixels. The JPEG, JPG, PNG,
or url. BMP, and TIFF formats are supported.

url No. String Image URL. Currently, the following


Set URLs are supported:
either ● Public network HTTP/HTTPS URL.
this
param ● URL provided by OBS. You need to
eter be authorized to use OBS data,
or including service authorization,
image temporary authorization, and
. anonymous public authorization.
For details, see Configuring Access
Permissions of OBS.
NOTE
● The API response time depends on the
image download time. If the image
download takes a long time, the API
call will fail.
● Ensure that the storage service where
the images to be detected reside is
stable and reliable. OBS is
recommended for storing image data.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 31


Optical Character Recognition
API Reference 4 APIs

Parameter Mand Type Description


atory

convert_unicode No Boolean ● true: The output is in the unicode


format.
● false: The output is in the zawgyi
format.
If this parameter is left blank or does
not exist, the output format is zawgyi
by default.

return_confidence No Boolean Whether to return the confidence.


Possible values are as follows:
true: Return the confidence.
false: Do not return the confidence.
If this parameter is not specified, the
system does not return the confidence
by default. If the input parameter is
not of the Boolean type, an error
message is displayed, indicating that
the parameter is invalid.

return_portrait_ima No Boolean Specifies whether to return the head


ge portrait. Possible values are as follows:
● true: The Base64 code of the head
portrait on the ID card is returned.
● false: The Base64 code of the head
portrait on the ID card is not
returned.
If this parameter is not transferred,
the default value false is used. That is,
the Base64 code of the head portrait
on the ID card is not returned.

return_portrait_loc No Boolean Specifies whether to return the


ation location of the head portrait on the ID
card. Possible values are as follows:
● true: The location of the head
portrait on the ID card is returned.
● false: The location of the head
portrait on the ID card is not
returned.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 32


Optical Character Recognition
API Reference 4 APIs

Parameter Mand Type Description


atory

return_idcard_type No Boolean Specifies whether to return the ID


card type. Possible values are as
follows:
● true: The ID card type is returned,
including the original ID card and
the copy of the ID card.
● false: The ID card type is not
returned.

Response Message
Table 4-12 describes the response parameters of Myanmar ID Card OCR.

Table 4-12 Response parameters

Parameter Type Description

result Object Calling result of a successful API call

side String Front or back of a national registration


card. Possible values are front and back.

class String ● ID card type. Possible values are as


follows:
● new_version: new version of ID card
● old_version: old version of ID card

nrc_id String ID card No.

issue_date String Date of issue

name String Name

father_name String Father's name

birth String Date of birth

bloodlines_religion String Ethnic group or religion

height String Height

blood_group String Blood type

card_id String National registration card number on the


back

nrc_id_back String National registration card ID on the back

profession String Occupation

address String Address

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 33


Optical Character Recognition
API Reference 4 APIs

Parameter Type Description

confidence Object Confidence information of a related field.


The value ranges from 0 to 1.
A higher confidence indicates a higher
reliability of the corresponding field
identified this time. In the statistical
sense, a higher confidence indicates a
higher accuracy.
The confidence is calculated by the
algorithm and is not equal to the
accuracy of the field.

portrait_image String Base64 code of the head portrait.


This parameter is available only when
return_portrait_image is set to true.

portrait_location Array of Location of the head portrait on the


objects original image.
This parameter is available only when
return_portrait_location is set to true.
The image is displayed in a list. The list
contains the two-dimensional coordinates
(x,y) of the four vertices in the head
portrait area. The origin of the
coordinates is the upper left corner of the
image. The x axis is horizontal, and the y
axis is vertical.

idcard_type String ID card type. Possible values are as


follows:
● normal: original ID card
● copy: copy of the ID card
This parameter is available only when
return_idcard_type is set to true.

error_code String Error code of a failed API call. For details,


see Error Code.
If the error code ModelArts.4204 is
displayed, refer to Why Is a Message
Stating "ModelArts.4204" Displayed
When the OCR API Is Called for
troubleshooting.
This parameter is not included when the
API is successfully called.

error_msg String Error message of a failed API call.


This parameter is not included when the
API is successfully called.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 34


Optical Character Recognition
API Reference 4 APIs

Example
NOTE

The endpoint is the request URL for calling an API. Endpoints vary according to services and
regions. For details, see Endpoints.
For example, the endpoint of Myanmar ID Card OCR in the AP-Hong Kong region is ocr.ap-
southeast-1.myhuaweicloud.com, so the request URL is https://ocr.ap-
southeast-1.myhuaweicloud.com/v1.0/myanmar-id-card.
● Request example (Method 1: Use a Base64-encoded image.)
POST https://{endpoint}/v1.0/myanmar-id-card

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAd...",
"convert_unicode": true,
"return_confidence": true,
"return_portrait_image": true,
"return_portrait_location": true,
"return_idcard_type": true
}
● Request example (Method 2: Use the URL redirecting to the image file.)
POST https://{endpoint}/v1.0/myanmar-id-card

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"url":"https://BucketName.obs.xxxx.com/ObjectName",
"convert_unicode": true,
"return_confidence": true,
"return_portrait_image": true,
"return_portrait_location": true,
"return_idcard_type": true
}

● Sample code for a Python request (For details about other languages, see the
following sample code or use the OCR SDK.)
# encoding:utf-8

import requests
import base64

url = "https://{endpoint}/v1.0/ocr/myanmar-id-card"
token = "Actual token value obtained by the user"
headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

imagepath = r'./data/myanmar-id-card-demo.png'
with open(imagepath, "rb") as bin_data:
image_data = bin_data.read()
image_base64 = base64.b64encode(image_data).decode("utf-8") # Base64 encoding of images.
payload = {"image": image_base64} # url or image.
response = requests.post(url, headers=headers, json=payload)
print(response.text)
● Successful response example (the front)
{
"result":{
"side": "front",
"nrc_id": "XXXXXXXX",
"issue_date": "၂၂.၂.၂၂၂၂",

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 35


Optical Character Recognition
API Reference 4 APIs

"name": "XXXX",
"father_name": "XXX",
"birth": "၂၂.၂၂.၂၂၂၂",
"bloodlines_religion": "၂၂၂၂၂၂၂၂၂",
"height": "၂'၂\"",
"blood_group": "၂၂",
"class": "new_version",
"confidence": {
"nrc_id": 0.7514,
"issue_date": 0.5385,
"name": 0.6641,
"birth": 0.5216,
"bloodlines_religion": 0.9774,
"height": 0.7526,
"blood_group": 0.7541
},
"idcard_type": "normal",
"portrait_image": "/9j/4AAQSkZJRgABAgEASABIABRHFGD...",
"portrait_location": [
[106, 178],
[369, 181],
[366, 448],
[108, 445]
]
}
}

● Successful response example (the back)


{
"result":{
"side": "back",
"card_id": "XXXXXXX",
"nrc_id_back": "",
"profession": "၂၂၂၂၂၂၂၂၂၂",
"address": "XXXXXXXX",
"class": "new_version",
"confidence": {
"card_id": 0.9878,
"nrc_id_back": 0.9595,
"profession": 0.9995,
"address": 0.9299
},
"idcard_type": "normal"
}
}

● Failed response example


{
"error_code": "AIS.0103",
"error_msg": "The image size does not meet the requirements."
}

Status Code
For details about the status code, see Status Code.

Error Code
For details about the error code, see Error Code.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 36


Optical Character Recognition
API Reference 4 APIs

4.5 Myanmar Driving License OCR


Function
Myanmar Driving License OCR recognizes characters on a Myanmar-issued driver's
license and returns the structured result in JSON format. For details about the
constraints on using this API, see Constraints. For details about how to use this
API, see Introduction to OCR.

Prerequisites
Before using Myanmar Driving License OCR, you need to apply for the service and
complete authentication. For details, see Applying for a Service and
Authentication.

URL
POST https://{endpoint}/v1.0/ocr/myanmar-driver-license

Table 4-13 Parameter description


Parameter Mandator Description
y

endpoint Yes Domain name or IP address of the server


bearing the REST service endpoint. The endpoint
varies between services in different regions. It
can be obtained from Endpoints.

Request Message
Table 4-14 describes the request parameters of Myanmar Driving License OCR.

Table 4-14 Request parameters


Parameter Mandatory Type Description

image No. Set String Base64 character string converted from


either this the image. The size cannot exceed 10
parameter MB.
or url. The narrow edge contains at least 15
pixels and the wide edge contains at
most 4,096 pixels. The JPEG, JPG, PNG,
BMP, and TIFF formats are supported.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 37


Optical Character Recognition
API Reference 4 APIs

Parameter Mandatory Type Description

url No. Set String Image URL. Currently, the following


either this URLs are supported:
parameter ● HTTP/HTTPS URL
or image.
● URL provided by OBS. You need to
be authorized to use OBS data,
including service authorization,
temporary authorization, and
anonymous public authorization. For
details, see Configuring Access
Permissions of OBS.
NOTE
● The API response time depends on the
image download time. If the image
download takes a long time, the API call
will fail.
● Ensure that the storage service where
the images to be detected reside is
stable and reliable. OBS is
recommended for storing image data.

convert_unic No Boolean ● true: The output is in the unicode


ode format.
● false: The output is in the zawgyi
format.
If this parameter is left blank or does
not exist, the output format is zawgyi
by default.

Response Message
Table 4-15 describes the response parameters of Myanmar Driving License OCR.

Table 4-15 Response parameters

Parameter Type Description

result Object Calling result of a successful API call

card_number String Number of the Myanmar driving


license

card_number_en String Number of the English driving license

name String Name, in Burmese

name_en String Name, in English

nrc_id String National registration card number, in


Burmese

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 38


Optical Character Recognition
API Reference 4 APIs

Parameter Type Description

nrc_id_en String National registration card number, in


English

Birth String Date of birth, in Burmese

birth_en String Date of birth, in English

blood_group String Blood type, in Burmese

blood_group_en String Blood type, in English

expiried_date String Date of expiry, in Burmese

expiried_date_en String Date of expiry, in English

confidence Object Confidence information of a related


field. The value ranges from 0 to 1.
A higher confidence indicates a higher
reliability of the corresponding field
identified this time. In the statistical
sense, a higher confidence indicates a
higher accuracy.
The confidence is provided by the
algorithm and is not equal to the
accuracy of the field.

error_code String Error code of a failed API call. For


details, see Error Code.
If the error code ModelArts.4204 is
displayed, refer to Why Is a Message
Stating "ModelArts.4204" Displayed
When the OCR API Is Called for
troubleshooting.
This parameter is not included when
the API is successfully called.

error_msg String Error message of a failed API call.


This parameter is not included when
the API is successfully called.

Example
NOTE

The endpoint is the request URL for calling an API. Endpoints vary according to services and
regions. For details, see Endpoints.
For example, the endpoint of Myanmar Driving License OCR in the AP-Hong Kong region is
ocr.ap-southeast-1.myhuaweicloud.com, so the request URL is https://ocr.ap-
southeast-1.myhuaweicloud.com/v1.0/ocr/myanmar-driver-license.
● Request example (Method 1: Use a Base64-encoded image.)
POST https://{endpoint}/v1.0/ocr/myanmar-driver-license

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 39


Optical Character Recognition
API Reference 4 APIs

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA...",
"convert_unicode": true
}

● Request example (Method 2: Use the URL redirecting to the image file.)
POST https://{endpoint}/v1.0/ocr/myanmar-driver-license

Request Header:
Content-Type: application/json
X-Auth-Token:
MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...
Request Body:
{
"url":"https://BucketName.obs.xxxx.com/ObjectName",
"convert_unicode": true
}

● Sample code for a Python request (For details about other languages, see the
following sample code or use the OCR SDK.)
# encoding:utf-8

import requests
import base64

url = "https://{endpoint}/v1.0/ocr/myanmar-driver-license"
token = "Actual token value obtained by the user"
headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

imagepath = r'./data/myanmar-driver-license-demo.png'
with open(imagepath, "rb") as bin_data:
image_data = bin_data.read()
image_base64 = base64.b64encode(image_data).decode("utf-8") # Base64 encoding of images.
payload = {"image": image_base64} # url or image.
response = requests.post(url, headers=headers, json=payload)
print(response.text)

● Response example

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 40


Optical Character Recognition
API Reference 4 APIs

● Failed response example


{
"error_code": "AIS.0103",
"error_msg": "The image size does not meet the requirements."
}

Status Code
For details about the status code, see Status Code.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 41


Optical Character Recognition
API Reference 4 APIs

Error Code
For details about the error code, see Error Code.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 42


Optical Character Recognition
API Reference 5 Appendix

5 Appendix

5.1 Status Code


The following table describes common status codes.

Status Coding Description


Code

100 Continue The server has received the initial part of the
request and the client should continue to
send the remaining part.
It is issued on a provisional basis while
request processing continues. It alerts the
client to wait for a final response.

101 Switching Protocols The requester has asked the server to switch
protocols and the server has agreed to do so.
The target protocol must be more advanced
than the source protocol.
For example, the current HTTPS protocol is
switched to a later version.

200 OK The server has successfully processed the


request.

201 Created The request has been fulfilled, resulting in


the creation of a new resource.

202 Accepted The request has been accepted, but the


processing has not been completed.

203 Non-Authoritative The server has successfully processed the


Information request, but is returning information that
may be from another source.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 43


Optical Character Recognition
API Reference 5 Appendix

Status Coding Description


Code

204 No Content The server has successfully processed the


request, but does not return any content.
The status code is returned in response to an
HTTP OPTIONS request.

205 Reset Content The server has successfully processed the


request, but does not return any content.
Unlike a 204 response, this response requires
that the requester reset the content.

206 Partial Content The server has successfully processed a part


of the GET request.

300 Multiple Choices There are multiple options for the location of
the requested resource. The response
contains a list of resource characteristics and
addresses from which the user or user agent
(such as a browser) can choose the most
appropriate one.

301 Moved Permanently The requested resource has been assigned a


new permanent URI, and the new URI is
contained in the response.

302 Found The requested resource resides temporarily


under a different URI.

303 See Other The response to the request can be found


under a different URI, and should be
retrieved using a GET or POST method.

304 Not Modified The requested resource has not been


modified. In such a case, there is no need to
retransmit the resource since the client still
has a previously-downloaded copy.

305 Use Proxy The requested resource must be accessed


through a proxy.

306 Unused The HTTP status code is no longer used.

400 Bad Request The request is invalid.


The client should not repeat the request
without modifications.

401 Unauthorized The authorization information provided by


the client is incorrect or invalid.

402 Payment Required This status code is reserved for future use.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 44


Optical Character Recognition
API Reference 5 Appendix

Status Coding Description


Code

403 Forbidden The server has received the request and


understood it, but the server is refusing to
respond to it.
The client should modify the request instead
of re-initiating it.

404 Not Found The requested resource cannot be found.


The client should not repeat the request
without modifications.

405 Method Not Allowed The method specified in the request is not
supported for the requested resource.
The client should not repeat the request
without modifications.

406 Not Acceptable The server cannot fulfill the request


according to the content characteristics of
the request.

407 Proxy Authentication This status code is similar to 401, but


Required indicates that the client must first
authenticate itself with the proxy.

408 Request Timeout The server has timed out waiting for the
request.
The client may repeat the request without
modifications at a later time.

409 Conflict The request could not be processed due to a


conflict.
For example, an edit conflict between
multiple simultaneous updates or the
resource that the client attempts to create
already exists.

410 Gone The requested resource has been deleted


permanently and is no longer available.
The status code indicates that the requested
resource has been deleted permanently.

411 Length Required The server refuses to accept the request


without a defined Content-Length.

412 Precondition Failed The server did not meet one of the
preconditions that the requester put on the
request.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 45


Optical Character Recognition
API Reference 5 Appendix

Status Coding Description


Code

413 Request Entity Too The request is larger than the server is
Large willing or able to process. The server may
close the connection to prevent the client
from continuing the request. If the server is
only temporarily unable to process the
request, the response will contain a Retry-
After header field.

414 Request URI Too Long The Request-URI is too long for the server to
process.

415 Unsupported Media The server is unable to process the media


Type format in the request.

416 Requested Range Not The requested range is invalid.


Satisfiable

417 Expectation Failed The server has failed to meet the


requirements of the Expect request-header
field.

422 Unprocessable Entity The request is well-formed but cannot be


processed due to semantic errors.

429 Too Many Requests The client has sent an excessive number of
requests to the server within a given time
(exceeding the limit on the access frequency
of the client), or the server has received an
excessive number of requests within a given
time (beyond its processing capability). In
this case, the client should resend the
requests at any point after the time specified
in the Retry-After header of the response.

500 Internal Server Error The server is able to receive the request but
unable to understand it.

501 Not Implemented The server does not support the function
required to fulfill the request.

502 Bad Gateway The server was acting as a gateway or proxy


and received an invalid response from the
upstream server.

503 Service Unavailable The requested service is invalid.


The client should not repeat the request
without modifications.

504 Gateway Timeout The request cannot be fulfilled within a


given time. This status code is returned to
the client only if the Timeout parameter is
specified in the request.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 46


Optical Character Recognition
API Reference 5 Appendix

Status Coding Description


Code

505 HTTP Version Not The server does not support the HTTPS
Supported protocol version used in the request.

5.2 Error Code


If an error occurs during API calling, no result is returned. You can locate the cause
of an error using the error code of each API. When an API call fails, HTTPS status
code 4xx or 5xx is returned. The returned message body contains a specific error
code and error message. If you are unable to identify the cause of an error,
contact HUAWEI CLOUDcustomer service and provide the error code so that we
can help you solve the problem as soon as possible.

Format of an Error Response Body


If an error occurs during API calling, an error code and a message will be
displayed. The following shows an error response body.
{
"error_msg": "The format of message is error",
"error_code": "AS.0001"
}

In the response body, error_code is an error code, and error_msg provides


information about the error.

Error Code
OCR is deployed on ModelArts and uses API Gateway (APIG). Therefore, OCR error
codes include ModelArts and APIG platform error codes.

If an error code starting with APIGW is returned after you call an API, rectify the
fault by referring to the instructions provided in Error Codes.

Mod Error Error Message. Description Solution


ule Code

OCR AIS.0101 The input The input Check the entered


parameter is parameter does parameter. For
invalid. not meet the details about the
requirements. input parameter
format of each API,
see Optical
Character
Recognition API
Reference > APIs >
Request
parameters.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 47


Optical Character Recognition
API Reference 5 Appendix

Mod Error Error Message. Description Solution


ule Code

AIS.0102 The image format The image Check the image


is not supported. format is not format. For details
supported. about the image
formats supported
by each service, see
Constraints.

AIS.0103 The image size The image size Check the image
does not meet the does not meet size. For details
requirements. the about the image
requirements. size supported by
each service, see
Constraints.

AIS.0104 The image is not The image is Check the image


supported or the not supported type and quality.
image quality is or is of poor
poor. quality.

AIS.0105 Recognition failed. Algorithm Contact the


calculation HUAWEI CLOUD
failed. support personnel.

Platf ModelArt Invalid token. The token is Check whether the


orm s.0203 invalid. token is correct.

ModelArt Token header The token is The HTTP request


s.4101 cannot be empty. empty. header does not
contain the token
request
authentication
information of x-
auth-token. Check
the request.

ModelArt Parse Token error. The token The token request


s.4102 failed to be authentication
parsed. information of x-
auth-token in the
HTTP request
header is incorrect.
Check the sent
request and token.

ModelArt Invalid Token The token is The token request


s.4103 header. invalid. authentication
information of x-
auth-token in the
HTTP request
header is incorrect.
Check the sent
request and token.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 48


Optical Character Recognition
API Reference 5 Appendix

Mod Error Error Message. Description Solution


ule Code

ModelArt Invalid Request The length of Check the request


s.4104 Content Length. the request body length.
body is invalid.

ModelArt The JSON format The JSON Check the JSON


s.4105 of the input data is format of the format of the
incorrect. request body is request body.
incorrect.

ModelArt Invalid The account is Check the user's


s.4106 authorization restricted. resources. For
request. details about the
account restriction
reason, see My
Account FAQ in
Help Center.

ModelArt Get user temp ak An exception Contact the


s.4107 sk error. occurred when HUAWEI CLOUD
obtaining the support personnel.
temporary
AK/SK.

ModelArt Request url need The request Check the service ID


s.4201 service id. URL does not in the request URL.
contain the
service ID.

ModelArt Request url format The request Check the request


s.4202 invalid. URL format is URL format.
invalid.

ModelArt Access denied! You Access Check the access


s.4203 do not have permission is permission.
permission. unavailable.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 49


Optical Character Recognition
API Reference 5 Appendix

Mod Error Error Message. Description Solution


ule Code

ModelArt Access api error! The API is not Subscribe to the


s.4204 Not subscribe this subscribed to. API. Rectify the
api. fault by following
the instructions
provided in Why Is
a Message Stating
"ModelArts.4204"
Displayed When
the OCR API Is
Called. If the API
has been enabled,
check whether the
region (or account)
where the service is
enabled is the same
as the region (or
account) where the
service is called. If
they are the same,
check whether the
URL of the API is
spelled correctly.

ModelArt The URL is not The external Check the format of


s.4601 allowed. URL is invalid. the entered
download address.

ModelArt Obtaining the file The file failed Check the network
s.4603 from the URL to be and URL.
failed. downloaded
from the
external URL.

ModelArt Query Obs agency The OBS Check whether the


s.4702 failed. agency failed OBS agency has
to be queried. been enabled for
the service.

ModelArt The Obs URL is The OBS URL is Check the OBS URL.
s.4703 invalid. invalid.

ModelArt Obtaining the file The OBS file Check the OBS file.
s.4704 from the OBS failed to be
failed. obtained.

ModelArt The file stored on The OBS file is Check the size of
s.4705 the OBS is oversized. the OBS file and
oversized. ensure that the file
does not exceed the
size limit.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 50


Optical Character Recognition
API Reference 5 Appendix

Mod Error Error Message. Description Solution


ule Code

ModelArt The Obs file is not The OBS file Check whether the
s.4706 exist. does not exist. corresponding file
exists.

APIG APIG. The API does not The API does Check whether the
0101 exist or has not not exist or has URL of the API is
been published in not been spelled correctly,
the environment. published. whether the
endpoint and the
corresponding URI
are correct, whether
the service is
deployed in the
target region, and
whether the HTTP
request method
(such as POST and
GET) is correct. For
details about the
endpoint, see
Endpoints.
For details about
the URI, see the API
page of each API.

APIG. Backend timeout. Request timed Rectify the fault by


0201 out. following the
instructions
provided in Why Is
a Message Stating
"APIG.0201"
Displayed When
the OCR API Is
Called.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 51


Optical Character Recognition
API Reference 5 Appendix

Mod Error Error Message. Description Solution


ule Code

APIG. Incorrect IAM The IAM 1. If the token fails


0301 authentication authentication to be parsed,
information. information is check the
incorrect. method for
1. decrypt obtaining the
token fail: token, whether
The token the request body
fails to be is correct,
parsed. whether the
token is correct,
2. token and whether the
expires: The environment for
token obtaining the
expires. token is the
3. verify aksk same as the
signature environment for
fail: The calling the token.
AK/SK 2. If the token
authenticati expires, obtain a
on fails. new token that is
valid
permanently.
3. Check whether
the AK/SK pair is
correct. (The SK
corresponding to
the AK is
incorrect. An
extra space is
entered in the
AK/SK pair.)
4. AK/SK-based
authentication
errors occur
frequently. If an
AK/SK pair fails
to be
authenticated for
more than five
consecutive
times, the AK/SK
pair is locked for
5 minutes (the
AK/SK-based
authentication is
considered as an
abnormal
authentication

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 52


Optical Character Recognition
API Reference 5 Appendix

Mod Error Error Message. Description Solution


ule Code

request within 5
minutes). After 5
minutes, the
AK/SK pair is
unlocked and re-
authenticated.
5. Check whether
the account is in
arrears or frozen.

APIG. The throttling The request Rectify the fault by


0308 threshold has been exceeds the following the
reached: policy user default rate instructions
over limit of the provided in Why Is
ratelimit,limit:XX,ti service. a Message Stating
me:1 minute. "APIG.0308"
Displayed When
the OCR API Is
Called.

Othe If other error codes are displayed, contact professional engineers.


r

5.3 Obtaining a Project ID


Obtaining a Project ID from the Management Console
1. Log in to the management console.
2. Move the cursor over your username in the upper right corner and click My
Credentials from the drop-down list.
3. On the My Credentials page, view the username and account name and view
projects in the project list.

Figure 5-1 Viewing the project ID

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 53


Optical Character Recognition
API Reference 5 Appendix

If there are multiple projects in one region, expand Region and view
subproject IDs in the Project ID column.

Obtaining a Project ID by Calling an API


The API for obtaining a project ID is GET https://{Endpoint}/v3/projects/.
{Endpoint} indicates the endpoint of IAM. For details about API authentication,
see Authentication.
The following is an example response. The value of id under projects is the project
ID.
{
"projects": [
{
"domain_id": "65382450e8f64ac0870cd180d14e684b",
"is_domain": false,
"parent_id": "65382450e8f64ac0870cd180d14e684b",
"name": "project_name",
"description": "",
"links": {
"next": null,
"previous": null,
"self": "https://www.example.com/v3/projects/a4a5d4098fb4474fa22https://support-
intl.huaweicloud.com/zh-cn/devg-apisign/api-sign-provide.htmlcd05f897d6b99"
},
"id": "a4a5d4098fb4474fa22cd05f897d6b99",
"enabled": true
}
],
"links": {
"next": null,
"previous": null,
"self": "https://www.example.com/v3/projects"
}
}

5.4 Obtaining an Account ID


An account ID (domain-id) is required for some URLs when an API is called. To
obtain an account ID, perform the following steps:
1. Register with and log in to the management console.
2. Hover the cursor on the username and choose My Credentials from the drop-
down list.
On the My Credentials page, view the Account ID.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 54


Optical Character Recognition
API Reference 5 Appendix

Figure 5-2 Viewing the account ID

5.5 Configuring Access Permissions of OBS


Multimedia files such as images and audio files in the Enterprise Intelligence (EI)
services can be directly processed by OBS. This reduces service usage costs,
shortens service response time, and improves service experience.

To ensure data security, a service can used authorized URLs (https://<bucket-


name>.<endpoint>/<object-name>) to access files stored on OBS after it is
granted with the permission. If not permitted, services cannot directly obtain user
data. To obtain the user data, public read authorization must be enabled or a
temporarily authorized URL must be provided.

Enabling Authorization for OCR


To use data in OBS, you need to enable OBS authorization. Log in to the Content
Moderation management console and click Service Management. Enable OBS
Authorization. After the authorization is enabled, you can use the authorized URL
to access the service.

Figure 5-3 OBS Authorization

NOTE

The region of OBS must be consistent with that of Image Recognition.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 55


Optical Character Recognition
API Reference 5 Appendix

Enabling Public Read Authorization


For details about how to enable public read authorization, see Permission Control
in the Object Storage Service Console Operation Guide. Then, you can access the
data on OBS using the URL after the corresponding files are uploaded to OBS. The
URL can also serve as EI services' API request parameter for using related service
APIs.

Using Temporary Request Authentication


Public read authorization is easy to use. However, when it is enabled, sensitive
information, such as private data, may be disclosed. In this scenario, the
temporary authorization function provided by OBS can be used.
OBS allows users to construct a specific URL for objects in OBS. The URL contains
authentication information. Any user can use the URL to access the specified
object in OBS, but the URL is valid only before the expiry time specified by Expires.
After a user issues temporary authorization, other users can perform desired
operations without knowing the user's secret access key.
For details about how to use the OBS temporary authorization function, see
section "Authorized Access" in the Object Storage Service SDK Reference.
Download the related SDK and sample code, and compile code to obtain the
related URL.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 56


Optical Character Recognition
API Reference A Change History

A Change History

Release Date What's New

2019-07-23 Added the following content:


Myanmar Driving License OCR

2019-04-29 This is the first official release.

Issue 02 (2019-07-23) Copyright © Huawei Technologies Co., Ltd. 57

You might also like