Updated on 2024-05-22 GMT+08:00

Calling an OCR API Locally

Use Passport OCR as an example to describe how you can use the OCR Python SDK.

To use the OCR Python SDK, perform the following steps:

Prerequisites

  • You have registered a Huawei ID and enabled Huawei Cloud services. Your account cannot be in arrears, frozen, or deregistered.
  • You have subscribed to Passport OCR by referring to Subscribing to an OCR Service.

Procedure

  1. Download and install the OCR Python SDK.

    The following uses PyCharm as an example to describe how to install the SDK.

    Create a project in PyCharm and click Terminal in the lower left corner. Run the following commands to install the SDK (the SDK supports Python 3 or later):
    # Install the huaweicloudsdkcore package.
    pip install huaweicloudsdkcore
    # Install the huaweicloudsdkocr package.
    pip install huaweicloudsdkocr

  2. Check whether the SDK has been installed properly.

    Choose File > Settings > Project > Python Interpreter in PyCharm and check whether the SDK has been installed properly.

  3. Obtain the SDK sample code of Passport OCR.
    1. Log in to the API Explorer and click Python on the Sample Code tab page.
    2. Configure request body parameters. Set image or url as input data.

    3. Copy the sample code to PyCharm.
  4. Obtain the AK and SK and replace <YOUR AK> and <YOUR SK> in the sample code with the AK and SK, respectively.

    Log in to the Access Keys page and create an access key or use an existing access key. The AK and SK are contained in the credentials.csv file.

  5. Run the sample code to obtain recognition results.