Flight Itinerary OCR
Function
Flight Itinerary OCR recognizes the text in a flight itinerary 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 Introduction to OCR.
Prerequisites
Before using Flight Itinerary 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/flight-itinerary
| 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
| 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. |
| 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 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 this parameter or image. | String | Image URL. Currently, the following URLs are supported:
NOTE:
|
Response Parameters
Response parameters and status codes vary in different recognition results. They are described as below.
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| result | FlightItineraryResult object | Calling result of a successful API call This parameter is not included when the API fails to be called. |
| Parameter | Type | Description |
|---|---|---|
| serial_number | String | Serial number |
| passenger_name | String | Name of a passenger |
| id_number | String | ID number |
| endorsements_restrictions | String | Remarks |
| order_number | String | Order ID |
| fare | String | Ticket price |
| caac_development_fund | String | Civil Aviation Administration of China (CAAC) development fund |
| fuel_surcharge | String | Fuel surcharge |
| other_taxes | String | Other taxes |
| total | String | Total amount |
| e_ticket_number | String | Electronic ticket number |
| check_code | String | Verification code |
| reference_information | String | Reference information |
| insurance | String | Insurance fee |
| agent_code | String | Code of a sales unit |
| issue_organization | String | Organization of issue |
| issue_date | String | Date of issue |
| itinerary_list | Array of ItineraryList objects | Flight itinerary list |
| 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 not equal to the accuracy, and is calculated through related algorithms. |
| Parameter | Type | Description |
|---|---|---|
| departure_station | String | Departure station |
| destination_station | String | Destination station |
| carrier | String | Carrier |
| flight | String | Flight number |
| cabin_class | String | Seat class |
| date | String | Date |
| time | String | Time |
| fare_basis | String | Fare type |
| effective_date | String | Effective date of a ticket |
| expiry_date | String | Date of expiry |
| baggage_allowance | String | Free baggage |
Status code: 400
| 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, Flight Itinerary 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/flight-itinerary. 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/flight-itinerary Request Header: Content-Type: application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." } - Request example (Method 2: Use the image URL.)
POST https://{endpoint}/v2/{project_id}/ocr/flight-itinerary Request Header: Content-Type: application/json X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... Request Body: { "url":"https://BucketName.obs.xxxx.com/ObjectName" } - 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/flight-itinerary" token = "Actual token value obtained by the user" headers = {'Content-Type': 'application/json', 'X-Auth-Token': token} imagepath = r'./data/flight-itinerary-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
{
"result": {
"serial_number": "12XXXXXXX22",
"passenger_name": "WANG/SAN",
"id_number": "GXXXXXX08",
"endorsements_restrictions": "Endorsement restriction recognized from the image",
"fare": "CNY 2340.00",
"caac_development_fund": "CN 100.00",
"fuel_surcharge": "XXXX",
"other_taxes": "",
"total": "CNY 2440.00",
"e_ticket_number": "73XXXXXXXX008",
"check_code": "3XXX",
"reference_information": "Reference information recognized from the image",
"insurance": "XXX",
"agent_code": "SXXXXX 00XXXX66",
"issue_organization": "Issue organization recognized from the image",
"issue_date": "2017-12-27",
"itinerary_list": [
{
"departure_station": "Departure station recognized from the image",
"destination_station": "Destination station recognized from the image",
"carrier": "Carrier recognized from the image",
"flight": "XXXXXX",
"cabin_class": "B",
"date": "2017-12-27",
"time": "13:00",
"fare_basis": "B",
"effective_date": "",
"expiry_date": "",
"baggage_allowance": "20K"
},
{
"departure_station": "Departure station recognized from the image",
"destination_station": "Destination station recognized from the image",
"carrier": "XXXX",
"flight": "XXXXXX",
"cabin_class": "B",
"date": "2017-12-29",
"time": "16:30",
"fare_basis": "B",
"effective_date": "",
"expiry_date": "",
"baggage_allowance": "20K"
}
],
"confidence":{
"serial_number": 0.9993,
"passenger_name": 0.9851,
"id_number": 0.9836,
"endorsements_restrictions": 0.998,
"fare": 0.9882,
"caac_development_fund": 0.993,
"fuel_surcharge": 0.9968,
"other_taxes": 0,
"total": 0.9999,
"e_ticket_number": 0.9631,
"check_code": 0.9985,
"reference_information": 1.0,
"insurance": 0.7749,
"agent_code": 0.9913,
"issue_organization": 0.7142,
"issue_date": 0.9936,
"itinerary_list": [
{
"departure_station": 1.0,
"destination_station": 0.9577,
"carrier": 0.9677,
"flight": 0.9957,
"cabin_class": 0.8744,
"date": 0.9993,
"time": 0.9978,
"fare_basis": 0.4006,
"effective_date": 0,
"expiry_date": 0,
"baggage_allowance": 0.9897
},
{
"departure_station": 1.0,
"destination_station": 0.9844,
"carrier": 0.9763,
"flight": 0.7453,
"cabin_class": 0.4239,
"date": 0.76,
"time": 0.7311,
"fare_basis": 0.4353,
"effective_date": 0,
"expiry_date": 0,
"baggage_allowance": 0.5265
}
]
}
}
} Status code: 400
Failure response example
{
"error_code": "AIS.0103",
"error_msg": "The image size does not meet the requirements."
} Status Codes
| Status Codes | 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.
Last Article: Toll Invoice OCR
Next Article: Application Examples
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.