Baidu AI open platform OCR call and open api qps result limit reached error code 18

Recently, the OCR function was used in the project. I found that the Baidu AI open platform has relatively strong capabilities, so I registered an account and called the relevant API.

First register on the open platform, and create an application, get AppID, API Key, Secret Key and other parameters.

When the above preparations are ready, start testing OCR-related functional modules.
First add dependencies to the pom.xml file.

		<dependency>
            <groupId>com.baidu.aip</groupId>
            <artifactId>java-sdk</artifactId>
            <version>4.16.13</version>
        </dependency>

Then start calling the API

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;

import org.json.JSONArray;
import org.json.JSONObject;
import com.baidu.aip.ocr.AipOcr;

public class BdImagUtil {

    public static final String APP_ID = "xxx";
    public static final String API_KEY = "xxx";
    public static final String SECRET_KEY = "xxx";

    public static void image2text() throws Exception{
        byte[] imageBytes = readImage();

        AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        JSONObject response = client.basicGeneral(imageBytes, new HashMap<String, String>());
        System.out.println("response is: \n" +  response);
        JSONArray jsonArray = response.getJSONArray("words_result");
        System.out.println(jsonArray.toString());
    }

    public static byte[] readImage() throws Exception {
        InputStream ins = BdImagUtil.class.getClassLoader().getResourceAsStream("11.jpg");
        byte[] bytes = new byte[ins.available()];
        ins.read(bytes);

        ins.close();
        return bytes;
    }

    public static void main(String[] args) throws Exception {
        image2text();
    }
}

The resulting code initially outputs:

response is:
{"error_msg":Open api qps result limit reached","error code":18}

The above error message shows that the qps call exceeds the upper limit, but obviously, we only have a java code, and there should be no problem that the qps is too large to exceed the upper limit.

After searching, we found that when we create an application, we still need to take the initiative to claim the free quota!

insert image description here
As shown above, there is a button to receive free resources, click this button to receive it.

Guess you like

Origin blog.csdn.net/bitcarmanlee/article/details/131463180