项目介绍
参加阿里云AI训练营的第4天,完成一个车辆检测系统
主要思路:用户上传身份证和受损车辆图片,识别结果返回前端,同时将数据存入数据库。
项目用到文档地址
阿里云达摩院视觉开放平台:https://vision.aliyun.com/
阿里云视觉开放平台 “车辆损伤识别” 地址:https://help.aliyun.com/document_detail/155002.html?spm=a2c4g.11174283.6.755.77e06bdfN9iMtt
项目模块1-各种识别服务
(1)说明
一开始的设想是用到身份证识别和车辆识别2个服务,但是发现同时导入 2 个依赖之后,有一些 jar 包会冲突,导致身份证识别的部分由于缺少一些 jar 包而不能正常运行。最后只用到了机动车识别和车辆损伤识别2个服务。
(2)导入项目依赖
这里的依赖我们使用较早的版本
<!-- 内容识别对应依赖 -->
<!-- https://mvnrepository.com/artifact/com.aliyun/objectdet -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>objectdet</artifactId>
<version>0.0.5</version>
</dependency>
<!-- 图片识别 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>ocr</artifactId>
<version>1.0.3</version>
</dependency>
之后同样要开通 “目标检测服务” 才能正常运行。
(3)创建 Client,Config类
虽然身份证识别部分会报错,但是这里依旧吧身份证识别部分的代码贴出来
CraService.java
@Value("${accessKeyId}")
private String accessKeyId;
@Value("${accessKeySecret}")
private String accessKeySecret;
// "内容识别" --> 导入这个类:import com.aliyun.objectdet20191230.Client;
private com.aliyun.objectdet.Client objectClient;
private com.aliyun.ocr.Client ocrClient;
private RuntimeObject runtimeObject;
private RuntimeOptions runTimeOperations;
@PostConstruct
public void initClient() throws Exception {
Config objectConfig = new Config();
objectConfig.type = "access_key";
objectConfig.regionId = "cn-shanghai";
objectConfig.accessKeyId = accessKeyId;
objectConfig.accessKeySecret = accessKeySecret;
// 注意这里的域名,我们是 “内容识别” 服务,所以开头是 objectdet=
objectConfig.endpoint = "objectdet.cn-shanghai.aliyuncs.com";
objectClient = new com.aliyun.objectdet.Client(objectConfig);
runtimeObject = new RuntimeObject();
com.aliyun.ocr.models.Config ocrConfig = new com.aliyun.ocr.models.Config();
ocrConfig.type = "access_key";
ocrConfig.regionId = "cn-shanghai";
ocrConfig.accessKeyId = accessKeyId;
ocrConfig.accessKeySecret = accessKeySecret;
// 注意这里的域名,我们是 “内容识别” 服务,所以开头是 objectdet=
ocrConfig.endpoint = "ocr.cn-shanghai.aliyuncs.com";
ocrClient = new com.aliyun.ocr.Client(ocrConfig);
runTimeOperations = new RuntimeOptions();
}
需要注意的是两个 Client 是不同的包下面的 Client 类,一个是 “内容识别” 的,另一个是 “图像识别” 的。
(4)调用关键 API
这里原本调用了3个服务,分别是 “身份证识别”,“机动车识别”,“车辆受损识别”&#