阿里云的通用文字识别-高精版识别接口地址:
通用文字识别 - 文字识别(OCR) - 阿里云
直接上代码
核心代码
package com.aliyun.sample;
import com.aliyun.tea.*;
import com.aliyun.ocr_api20210707.*;
import com.aliyun.ocr_api20210707.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.darabonba.stream.*;
public class Sample {
public static com.aliyun.ocr_api20210707.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config()
// 您的AccessKey ID
.setAccessKeyId(accessKeyId)
// 您的AccessKey Secret
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
return new com.aliyun.ocr_api20210707.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List args = java.util.Arrays.asList(args_);
com.aliyun.ocr_api20210707.Client client = Sample.createClient("client id", "client secrect");
java.io.InputStream bodySyream = com.aliyun.darabonba.stream.Client.readFromFilePath("D:\work\doc\1.jpg");
RecognizeAdvancedRequest recognizeAdvancedRequest = new RecognizeAdvancedRequest()
.setBody(bodySyream);
// 复制代码运行请自行打印 API 的返回值
RecognizeAdvancedResponse response= client.recognizeAdvanced(recognizeAdvancedRequest);
System.out.println(response.getBody().getData());
}
}
pom.xml配置文件
4.0.0 com.aliyun sample1.0.0 jar sample Alibaba Cloud SDK Code Sample for Java https://github.com/aliyun/alibabacloud-code-sample http://www.apache.org/licenses/LICENSE-2.0.txt aliyundeveloper Aliyun SDK aliyunsdk@aliyun.com sonatype-nexus-snapshots https://s01.oss.sonatype.org/content/repositories/snapshots sonatype-nexus-staging https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ com.aliyun ocr_api202107071.1.1 com.aliyun darabonba-stream0.0.1 com.aliyun tea-openapi0.2.0 com.aliyun tea-console0.0.1 com.aliyun tea-util0.2.13 com.aliyun tea1.1.14 org.apache.maven.plugins maven-compiler-plugin3.6.1 7 7 org.apache.maven.plugins maven-gpg-plugin1.6 sign-artifacts verify sign org.sonatype.plugins nexus-staging-maven-plugin1.6.3 true sonatype-nexus-staging https://s01.oss.sonatype.org/ trueorg.apache.maven.plugins maven-javadoc-plugin3.1.1 UTF-8 none org.apache.maven.plugins maven-surefire-plugin2.22.1 org.apache.maven.plugins maven-assembly-plugin2.4.1 jar-with-dependencies true com.aliyun.sample.Sample make-assembly package single
运行后输出内容为:



