Recognize train tickets with OCR

Updated at:

1. Component introduction

Note

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

Note

For more information about each input, see the component's panel in the application flow editor.

3. Outputs

Note

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

  1. Set **AI engine** to **Alibaba Cloud OCR**.

  2. For **Path of the image file to recognize**, enter the path of the image file. This example uses the following image.

    image

  3. Keep the default values for the advanced options.

4.2. Example execution result

5. Flow example

5.1. Build a flow

  1. Use the Recognize Train Ticket component to specify the path of the image file to recognize.

  2. 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.

  3. 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.

  4. Use the Record Log component to print the retrieved recognition result.

  5. In the failure branch, use the Record Log component to print the error message. image

5.2. Execution result

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