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.
- Passports issued by different countries can be recognized by detecting and extracting the machine-readable code at the bottom of the first page.
- Only images in PNG, JPG, JPEG, BMP, or TIFF format can be recognized.
- No side of the image can be smaller than 15 or larger than 4,096 pixels.
- 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.
- A passport can be rotated to any angle.
- The passport in the image can be moderately distorted, but the aspect ratio cannot be distorted by more than 10%.
- 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:
- Image
- Import the Base64 code of an image.
- You can use an online transcoding tool or the base64.b64encode function in Python to obtain the Base64 code of an image.
- URL
- Import the URL of an image.
- Use an HTTP/HTTPS URL, for example, https://support.huaweicloud.com/intl/zh-cn/api-ocr/zh-cn_image_0288040512.png.
- 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