The Baidu Table OCR API is a powerful service provided by Baidu, which can extract and convert table data from images into an editable table format. This API supports various image formats, offers high-precision recognition, and supports asynchronous calls, ensuring efficient operation in high-concurrency environments.
To use the Baidu Table OCR API, you first need to register for a Baidu developer account and create a new application to obtain the API keys and identification information. You can complete the registration by visiting the Baidu Developer Center:
After registering and logging in, go to the console and create a new application under the "OCR" service. During the application setup, you will need to provide a name, description, and choose the appropriate API service type.
After creating the service, you can find and retrieve the API key (AK) and secret key (SK) from the console. These keys are crucial for API calls, so it’s important to keep them safe and avoid leaking them.
To facilitate the use of Baidu AI API, you can install the Baidu AI PHP SDK via Composer. The installation command is as follows:
Once installed, include the Baidu AI SDK autoload class in your PHP project:
Before calling the Baidu Table OCR API, you need to obtain the API key (AK and SK) and create an AipOcr instance:
Before calling the API, define the image path for recognition, typically through PHP’s $_FILES variable to get the uploaded image file:
Next, you can call the Baidu Table OCR API to recognize the table data from the image. Since table recognition can take some time, we will use asynchronous calls:
Once the task is completed, you can retrieve and process the table recognition results. The results can be saved in CSV format or another format for easy data import and management, or displayed directly to the front-end user:
Following the steps in this article, you can easily integrate PHP with the Baidu Table OCR API to convert table data from images into editable text formats. Be sure to protect your API keys and ensure the security of the file upload process.