How to Use OCR

Optical Character Recognition (OCR) identifies and extracts text from images and converts the text into an editable JSON format. OCR provides this text recognition through open APIs.

Process for using OCR

Notice

You have programming capabilities and are familiar with Java, Python, iOS, Android, and Node.js.

You need to call APIs to use OCR and transmit the results to the service system, or to convert the results from JSON to TXT or Excel form.

Subscribing to an OCR Service

Pay-per-Use Billing

1. Go to the OCR homepage and click Try Now to go to the OCR console.

2. On the Overview page, select your destired OCR service and click Subscribe in the Operation column. In this case, the pay-per-use billing mode is used.

Figure 1 Subscribing to your desired OCR service

3. If you want to use data stored on OBS, authorize OCR to access OBS on the Overview page.

Figure 2 Authorizing OCR to access OBS

NOTE:

If you no longer need to use an OCR service, you can unsubscribe it from the OCR console. After you subscribe to an OCR service, you will be billed for the service on a pay-per-use basis by default. You are billed only when your API is called successfully (status code 2xx is returned). For details about the pricing, see Pricing Details.

If you have not subscribed to an OCR service yet, an error message with error code "ModelArts.4204" will be displayed when you call the OCR API.

After subscribing to the service, you can use the service as needed by referring to Data Requirements and Calling APIs or SDKs.

Purchasing a Package

1. Go to the OCR homepage and click Try Now to go to the OCR console.

2. On the Overview page, select your desired service and click Buy Package in the Operation column. In this case, the package billing mode is used. After your package quota is used up, the billing mode automatically changes to pay-per-use.

If the service is subscribed to successfully, Subscribed is displayed in the Subscription column.

3. If you want to use data stored on OBS, authorize OCR to access OBS on the Overview page.

NOTE:

After you purchase a package, an API call is counted only when it is successfully called (status code 2xx is returned). For details about pricing, see Pricing Details.

If you have not subscribed to an OCR service yet, an error message with error code "ModelArts.4204" will be displayed when you call the OCR API.

After subscribing to the service, you can use the service as needed by referring to Data Requirements and Calling APIs or SDKs.

Preparing Data (OCR)

Data Requirements

Multiple factors such as technology and cost impose the following constraints on your use of OCR services.

Take the passport OCR API as an example. For details about constraints on calling other OCR APIs, see Constraints.

  1. Passports issued by different countries can be recognized by detecting and extracting the machine-readable code at the bottom of the first page.
  2. Only images in PNG, JPG, JPEG, BMP, or TIFF format can be recognized.
  3. No side of the image can be smaller than 15 or larger than 4,096 pixels.
  4. The information page of the passport to be recognized must occupy more than 25% of the image. When scanning a passport, ensure that the entire page is displayed in the image.
  5. A passport can be rotated to any angle.
  6. The passport in the image can be moderately distorted, but the aspect ratio cannot be distorted by more than 10%.
  7. Illuminated or dark images can be recognized, but the accuracy may be compromised.

Data Import Methods

When OCR APIs or SDKs are used, data is imported in either of the following methods:

  1. Image
  2. Import the Base64 code of an image.
  3. You can use an online transcoding tool or the base64.b64encode function in Python to obtain the Base64 code of an image.
  4. URL
  5. Import the URL of an image.
  6. Use an HTTP/HTTPS URL, for example, https://support.huaweicloud.com/intl/zh-cn/api-ocr/zh-cn_image_0288040512.png.
  7. Upload the image to Huawei Cloud OBS and use the URL provided by OBS. To use OBS data, authorize OCR to access OBS, including service authorization, temporary authorization, and anonymous public authorization. For details, see Configuring the Access Permission of OBS.

OCR FAQs

API & Billing & Subscription

  • How Do I View the API Usage?

    1. Log in to the OCR console.

    2. In the navigation pane on the left, choose Service Monitoring, and view the API usage.

  • Why Is the Actual Number of API Calls Inconsistent with the Record Displayed on the Management Console?

    The OCR console only records the number of successful API calls. The number of failed API calls is not recorded.

    To view the number of failed calls, perform the following operations:

    1. Log in to the management console.

    2. On the console home, choose Optical Character Recognition. The Optical Character Recognition console is displayed.

    3. Click the target service. Click View Monitoring Graph to go to the Cloud Eye console and view detailed service usage such as the number of successful or failed API calls.

  • What Do I Do If the Subscribe Button Is Dimmed?

    Symptom

    After logging in to the OCR console, I cannot subscribe to an OCR service because the Subscribe button is dimmed.

    Possible Causes

    The possible cause is that the current user is an IAM user who does not have the permission to subscribe to the service. An account pays for and owns the resources and has full access permissions for the resources.

    Solution

    Log in to the OCR console using an account and subscribe to OCR.

  • How Do I Select a Region for an OCR Package?

    Resource packages in different regions are isolated. Select a region according to your business requirements. For details about the regions where services are deployed, see Endpoints.

    Determine the service region before purchasing a service package.

  • Can a Package Be Refunded After Being Purchased?

    The package cannot be refunded after being purchased.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more