京东云OCR文字识别
在网上看的京东云人工智能挺多技术的,这里记录下,留作今后学习使用!
引入京东云人工智能的依赖
<dependency>
<groupId>com.jdcloud.apigateway</groupId>
<artifactId>sdk</artifactId>
<version>0.4.0</version>
</dependency>
配置properties文件
accessKey和secretKey的获取在我另一篇博客里 京东云OSS存取 可以拿到
各功能代码
把properties文件的三个参数拿到
这里是采用postnam来测试
需要导入的包有:
import com.google.api.client.http.HttpResponse;
import com.jdcloud.apigateway.signature.JdcloudSDKClient;
import com.jdcloud.sdk.utils.BinaryUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static com.jdcloud.sdk.http.Protocol.HTTP;
身份证识别
/**
* 身份证识别
* @param map
* @return
*/
@RequestMapping("/idCard")
public String idCardOcr(@RequestBody Map<String,Object> map){
String path = "/jdai/ocr_idcard";
String method = "POST";
Map<String, String> headers = new HashMap<>();
Map<String, Object> queryMap = new HashMap<>();
// 身份证路径
String filepath = String.valueOf(map.get("filepath"));
File file = new File(filepath);
try {
HttpResponse response = JdcloudSDKClient.upload(accessKey, secretKey, HTTP, endPoint, path, method, headers, queryMap, file);
System.err.println(new String(BinaryUtils.toByteArray(response.getContent()