This document describes how to use API 3.0 Explorer to debug OCR APIs online and quickly integrate the Tencent Cloud SDK corresponding to the APIs into your local project.
Operation Steps
Complete the Tencent Cloud OCR API call in just three steps.
Step 1. Activate the OCR Service
Before using OCR-related APIs, you need to enter the OCR console, read the "OCR Terms of Service", agree by checking the box, and click Activate Now to instantly activate services such as General Text, Card and Certificate Text, Bills and Invoices, etc..
After the service is successfully activated, you will get the free tiers of calls for each service, which can be viewed on the Resource Pack Management page. In addition, you can also purchase resource packages for OCR services on the OCR purchase page. After the free tiers and number of resource package calls are used up, API calls will be billed in the pay-as-you-go mode and settled monthly. For billing details, see the OCR Purchase Guide.
Step 2. Debug the OCR API
After the OCR service is successfully activated, go to the OCR API 3.0 Explorer online debugging page, select the API you need to call, and fill in the Input Parameters.
You can view the specific meanings of the input parameters for the corresponding API in the [parameter description] tab of the API 3.0 Explorer interface.
Among them, the Region parameter is a required parameter for each API, indicating the region where the OCR service resources are located. Click the Region dropdown box to select Tencent Cloud servers in different regions. It is recommended to choose a region close to the access point IP address: for example, if your access point is in Shenzhen, it is recommended to choose the South China region (Guangzhou).
After filling in the input parameters, select the code generation tab to see the automatically generated code in different programming languages (supporting Java, Python, Node.js, PHP, GO, .NET, C++). Some field information and filled content in the generated code are associated. If you need to adjust the input parameters, you can modify the parameter values on the left and regenerate the code.
After filling in the input parameters, select the online calling tab, and click the send request button to make a real request for debugging and reference.
Step 3. Integrate the OCR SDK
Make sure the local dependency environment meets the following conditions:
Programming Environment
SDK Integration Requirements
Node.js
Version 7.10.1 or later is required.
Python
Version 2.7 to 3.6 is required.
Java
JDK 7 or above is required.
Go
Go 1.9 or above is required.
.Net
.NET Framework 4.5+ and .NET Core 2.1 are required.
PHP
Version 5.6.33 or later is required.
C++
The C++ compiler v4.8 or above and the build tool cmake v3.0 or above are required. Currently, only the Linux environment is supported, while Windows is not.
Install the Tencent Cloud OCR SDK corresponding to the local dependency environment. The following example demonstrates the SDK installation and usage for Node.js. For other languages, please refer to the Tencent Cloud SDK Integration Manual.
(1) Installing through npm (recommended): npm is the package management tool for Node.js. Execute the following installation command:
npminstall tencentcloud-sdk-nodejs --save
(2) Installing through the source package: Go to the GitHub repository address and download the source package. Decompress the source package to an appropriate location in your project.
After the SDK installation is complete, you can reference the code automatically generated by API 3.0 Explorer in your project code. For example, a simple demo in Node.js is as follows:
// Call the API (Action) you want to access through the client object; you need to pass in the request object (Params) and the response callback function
// That is: client.Action(Params).then(res => console.log(res), err => console.error(err))
client.IDCardOCR(params).then(
(data)=>{
console.log(data)
},
(err)=>{
console.error("error", err)
}
)
Notes
When calling common parameters with the SDK, only the Region field needs attention. It is recommended to use "ap-guangzhou" for both the domain name and Region.
For Base64-encoded image or video, remove the data:image/jpg;base64, prefix and the line break \n. If the following error occurs when calling the SDK:
You need to manually configure the signature type:
signMethod:"TC3-HMAC-SHA256",// Specify the signature algorithm "TC3-HMAC-SHA256". The default value is HmacSHA256
If the API request content exceeds 1M, only V3 Authentication (TC3-HMAC-SHA256) can be used.
The OCR API 3.0 SDK currently supports Node.js, Python, Java, PHP, Go, .Net, and C++. If you use other programming languages or do not want to use the Tencent Cloud SDK, you need to complete V3 authentication for API calls. For implementation details, refer to the Github samples. We recommend using the string signature generation tool in API 3.0 Explorer for verification.