Vehicle License OCR

Function

Vehicle License OCR recognizes the text on the home and side pages of a vehicle license and returns the recognition 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.

If the image contains multiple cards and tickets, call Auto Classification OCR.

Prerequisites

Before using Vehicle License OCR, you need to apply for the service and complete authentication. For details, see Subscribing to OCR and Authentication.

URI

POST https://{endpoint}/v2/{project_id}/ocr/vehicle-license

Table 1 Path parameters

Parameter

Mandatory

Description

endpoint

Yes

Domain name or IP address of the server bearing the REST service endpoint. The endpoint varies depending on services in different regions. For more details, see Endpoints.

For example, the endpoint of OCR in the CN North-Beijing4 region is ocr.cn-north-4.myhuaweicloud.com.

project_id

Yes

Project ID, which can be obtained from Obtaining a Project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token

During API authentication using a token, the token is added to requests to obtain permissions for calling the API. The value of X-Subject-Token in the response header is the obtained token.

Content-Type

Yes

String

MIME type of the request body. The value is application/json.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

image

No. Set either this parameter or url.

String

Base64 character string converted from the image. The size cannot exceed 10 MB. The narrow edge contains at least 100 pixels and the wide edge contains at most 8,000 pixels. Images only in JPEG, JPG, PNG, BMP, or TIFF format can be recognized.

url

No. Set either this parameter or image.

String

Image URL. Currently, the following URLs are supported:

  • Public network: 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.

side

No

String

  • front: first page of a vehicle license
  • back: second page of a vehicle license

If this parameter is left blank or not included, the system automatically recognizes whether the first page of a vehicle license. To ensure accuracy, you are advised to set this parameter.

return_issuing_authority

No

Boolean

Whether to return the issuing authority. Possible values are as follows:

  • true: The issuing authority will be returned.
  • false: The issuing authority will not be returned.

If this parameter is not specified, the system does not return the issuing authority by default. If the input parameter is not of the Boolean type, an error message is displayed, indicating that the parameter is invalid.

Response Parameters

Response parameters and status codes vary in different recognition results. They are described as below.

Status code: 200

Table 4 Response body parameter

Parameter

Type

Description

result

VehicleLicenseResult object

Calling result of a successful API call

This parameter is not included when the API fails to be called.

Table 5 VehicleLicenseResult

Parameter

Type

Description

number

String

License plate number

vehicle_type

String

Vehicle type

name

String

Owner of the vehicle

address

String

Address

use_character

String

Use character

model

String

Model of the vehicle

engine_no

String

Engine number

vin

String

Vehicle identification number (VIN)

register_date

String

Register date

issue_date

String

Date of issue

issuing_authority

String

Issuing authority

file_no

String

File number

approved_passengers

String

Approved passenger capacity

gross_mass

String

Gross mass

unladen_mass

String

Unladen mass

approved_load

String

Approved load

dimension

String

Overall dimensions

traction_mass

String

Traction mass

remarks

String

Remarks

inspection_record

String

Inspection record

code_number

String

Barcode

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error code of a failed API call. For details, see Error Codes.

If error code ModelArts.4204 is displayed, refer to Why Is a Message Stating "ModelArts.4204" Displayed When the OCR API Is Called?

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

error_msg

String

Error message returned when the API fails to be called

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

Request Example

  • The endpoint is the request URL for calling an API. Endpoints vary depending on services and regions. For details, see Endpoints.

    For example, Vehicle License OCR is deployed in the CN North-Beijing4 region. The endpoint is ocr.cn-north-4.myhuaweicloud.com. The request URL is https://ocr.cn-north-4.myhuaweicloud.com/v2/{project_id}/ocr/vehicle-license. project_id is the project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

  • For details about how to obtain a token, see Making an API Request.
  • Request example (Method 1: Use the image Base64 string.)
    POST https://{endpoint}/v2/{project_id}/ocr/vehicle-license
     Request Header:   
     Content-Type: application/json   
     X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...      
     Request Body:
     {
        "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAg...",
        "side":"front",
        "return_issuing_authority":true
      }
  • Request example (Method 2: Use the image URL.)
    POST https://{endpoint}/v2/{project_id}/ocr/vehicle-license
     Request Header:   
     Content-Type: application/json
     X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... 
     Request Body:
     {
         "url":"https://BucketName.obs.xxxx.com/ObjectName",
         "side":"back"
     }
  • Sample code for a Python 3 request (For codes in other languages, refer to the following sample or use OCR SDK.)
    # encoding:utf-8
    
    import requests
    import base64
    
    url = "https://{endpoint}/v2/{project_id}/ocr/vehicle-license"
    token = "Actual token value obtained by the user"
    headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}
    
    imagepath = r'./data/vehicle-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)

Example Response

Status code: 200

Successful response example (front page)

{
  "result":{
       "number":"Plate number recognized from the image",
       "vehicle_type":"Vehicle type recognized from the image",
       "name": "Owner of the vehicle recognized from the image",
       "address":"Address recognized from the image",
       "use_character": "Use character recognized from the image",
       "model": "Vehicle model recognized from the image",
       "vin":"LXDXXXXXXXX8998",
       "engine_no":"27XXXXD",
       "register_date":"2013-05-08",
       "issue_date":"2013-05-08",
       "issuing_authority": "Issuing authority recognized from the image"
  }
}

Successful response example (back page)

{
  "result":{
       "number":"Plate number recognized from the image",
       "file_no": "File No. recognized from the image",
       "approved_passengers": "Number of approved passengers recognized from the image",
       "gross_mass": "Gross mass recognized from the image",
       "unladen_mass": "Unladen mass recognized from the image",
      "approved_load": "Approved load recognized from the image",
       "dimension": "Dimensions recognized from the image",
       "traction_mass": "Traction mass recognized from the image",
       "remarks": "Remarks recognized from the image",
       "inspection_record": "Inspection record recognized from the image",
       "code_number": "Code number recognized from the image"

  }
}

Status code: 400

Failure response example

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

Status Codes

Status Code

Description

200

Success response

400

Failure response

For details about status codes, see Status Codes.

Error Codes

For details about error codes, see Error Codes.