AI智能
改变未来

京东云人工智能–OCR文字识别(身份证识别,车牌识别,银行卡识别,营业执照识别,通用文字识别)


京东云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())));} catch (IOException e) {System.out.println(e.getMessage());}return \"\";}

车牌识别

/*** 车牌识别* @param map* @return*/@RequestMapping(\"/licensePlate\")public String licensePlate(@RequestBody Map<String,Object> map){String path = \"/jdai/license_plate\";String method = \"POST\";Map<String, String> headers = new HashMap<>();Map<String, Object> queryMap = new HashMap<>();queryMap.put(\"Content-Type\", \"application/json\");String filepath = String.valueOf(map.get(\"filepath\"));String body = \"{\\\"imageUrl\\\":\\\"\" + filepath + \"\\\"}\";try {HttpResponse response = JdcloudSDKClient.execute(accessKey, secretKey, HTTP, endPoint, path, method, headers, queryMap, body);System.err.println(new String(BinaryUtils.toByteArray(response.getContent())));} catch (IOException e) {System.out.println(e.getMessage());}return \"\";}

银行卡识别

/*** 银行卡识别* @param map* @return*/@RequestMapping(\"/bankCard\")public String bankCard(@RequestBody Map<String,Object> map){String path = \"/jdai/ocr_bankcard\";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())));} catch (IOException e) {System.out.println(e.getMessage());}return \"\";}

营业执照识别

/*** 营业执照识别* @param map* @return*/@RequestMapping(\"/business\")public String business(@RequestBody Map<String,Object> map){String path = \"/jdai/ocr_business\";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.out.println(new String(BinaryUtils.toByteArray(response.getContent())));} catch (IOException e) {System.out.println(e.getMessage());}return \"\";}

通用文字识别

/*** 通用文字识别* @param map* @return*/@RequestMapping(\"/universalRecognition\")public String universalRecognition(@RequestBody Map<String,Object> map){String path = \"/jdai/ocr_universal\";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.out.println(new String(BinaryUtils.toByteArray(response.getContent())));} catch (IOException e) {System.out.println(e.getMessage());}return \"\";}

各功能测试

这里说明一下,因为没有做返回操作,只是在控制台打印出来调用返回的结果.然后把json串拿到postnam里格式化展示出来!

身份证识别


返回结果:

车牌识别

这里有点问题.现在也没有想明白.刚才调通了身份证,然后把车牌识别的入参写好了,调用会报个错误:

再调用一下车辆识别接口(什么都不要动)就会成功!


但是又有个问题,放的是本的的一个车牌路径,他提示是找不到图片.所以只好在京东云调试接口的地方拿个网络路径


测试结果是OK的!

银行卡识别

连接调用还是会有问题.还是那个问题


测试结果是OK的!

营业执照识别

连接调用还是会有问题.还是那个问题


测试结果是OK的!

通用文字识别

扫瞄的图片为:

发送请求:

请求结果:

{\"code\": \"10000\",\"charge\": true,\"msg\": \"查询成功,扣费\",\"result\": {\"message\": \"success\",\"request_id\": \"7614b67b978fb13f4fa56054d8e1c159\",\"resultData\": [{\"text\": \"十代酷靳”轻薄随行\",\"location\": {\"x\": 343,\"y\": 70,\"width\": 427,\"height\": 50},\"probability\": 0.6277908086776733},{\"text\": \"灵越5000轻薄本\",\"location\": {\"x\": 519,\"y\": 129,\"width\": 249,\"height\": 32},\"probability\": 0.99813312292099},{\"text\": \"立即抢\",\"location\": {\"x\": 613,\"y\": 287,\"width\": 124,\"height\": 34},\"probability\": 0.9996627569198608},{\"text\": \"(品牌)\",\"location\": {\"x\": 449,\"y\": 130,\"width\": 69,\"height\": 33},\"probability\": 0.9999868869781494},{\"text\": \"酷靳\",\"location\": {\"x\": 519,\"y\": 220,\"width\": 61,\"height\": 28},\"probability\": 0.9941646456718445},{\"text\": \"轻薄\",\"location\": {\"x\": 607,\"y\": 190,\"width\": 59,\"height\": 27},\"probability\": 0.9999877214431763},{\"text\": \"独显\",\"location\": {\"x\": 689,\"y\": 191,\"width\": 61,\"height\": 26},\"probability\": 0.9999872446060181},{\"text\": \"有型\",\"location\": {\"x\": 607,\"y\": 220,\"width\": 60,\"height\": 27},\"probability\": 0.9999912977218628},{\"text\": \"拓展\",\"location\": {\"x\": 690,\"y\": 221,\"width\": 61,\"height\": 28},\"probability\": 0.9999703168869019},{\"text\": \"十代\",\"location\": {\"x\": 519,\"y\": 191,\"width\": 61,\"height\": 28},\"probability\": 0.9998642206192017}],\"code\": 0}}

欢迎大佬们留言评论,共同学习!!!感谢!!!

============================
原创文章,转载注明出处!

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 京东云人工智能–OCR文字识别(身份证识别,车牌识别,银行卡识别,营业执照识别,通用文字识别)