Recognize train tickets with OCR
1. Component introduction
Required preceding components: None
Recommended succeeding component: Conditional Branch. Use a branch condition to check if the OCR call is successful and to configure the subsequent flow.
Use this component to recognize key fields on train tickets with OCR, such as the ticket number, departure station, and arrival station (example).
2. Inputs
For more information about each input, see the component's panel in the application flow editor.
3. Outputs
For more information about each output, see the component's panel in the application flow editor.
3.1. Key API return results
This output returns a dictionary that contains the key recognition results from the API. The following table describes the key-value pairs in the dictionary.
Key |
Key description |
Value data type |
departureStation |
Departure station |
String |
arrivalStation |
Arrival station |
String |
trainNumber |
Train number |
String |
departureTime |
Departure time |
String |
seatNumber |
Seat number |
String |
fare |
Fare |
String |
seatType |
Seat type |
String |
passengerInfo |
Passenger information |
String |
passengerName |
Passenger name |
String |
ticketNumber |
Ticket number |
String |
ticketCode |
Ticket code |
String |
saleInfo |
Ticketing station information |
String |
3.2. Error message
This output returns the error code and error message as a string. For more information, see the OCR Error Center.
https://next.api.aliyun.com/document/ocr-api/2021-07-07/errorCode
4. Component usage example
4.1. Component configuration example
Set **AI engine** to **Alibaba Cloud OCR**.
For **Path of the image file to recognize**, enter the path of the image file. This example uses the following image.

Keep the default values for the advanced options.
4.2. Example execution result
5. Flow example
5.1. Build a flow
Use the Recognize Train Ticket component to specify the path of the image file to recognize.
Use the Conditional Branch component with the condition `v_recognize_traininvoice_success_1` equals the Boolean value `True` to determine whether the OCR call is successful.
In the success branch, use the Get Value of Specified Key component to retrieve a specified key from the key API return result dictionary. This example retrieves the `passengerInfo` (Passenger information) key.
Use the Record Log component to print the retrieved recognition result.
In the failure branch, use the Record Log component to print the error message.

5.2. Execution result
As shown in the following figure, after the OCR call succeeds, the recognition result is printed in the log panel.