<dependency>
<groupId>com.baidu.aip</groupId>
<artifactId>java-sdk</artifactId>
<version>4.16.11</version>
</dependency>
import java.util.*;
import org.json.JSONException;
import org.json.JSONObject;
import com.baidu.aip.ocr.AipOcr;
/**
* 图片文字提取
*/
public class TextExtraction {
//设置APPID/AK/SK
public static final String APP_ID = "xxx";
public static final String API_KEY = "xxxxxx";
public static final String SECRET_KEY = "xxxxx";
public static void main(String[] args) throws JSONException {
// 初始化一个AipOcr
AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
// 可选:设置网络连接参数
client.setConnectionTimeoutInMillis(2000);
client.setSocketTimeoutInMillis(60000);
// 调用接口
String path = "D:/test/test.jpg";
JSONObject res = client.basicGeneral(path, new HashMap<String, String>());
System.out.println(res.toString(2));
}
}
注:APP_ID,API_KEY,SECRET_KEY换成自己的。
图片的每一行字放在一个对象里面
?