有一说一,在五天阿里云视觉训练营中,身为菜鸟的我只学会了调用外部API和使用maven,我很开心,感谢阿里。
这次只在后端实现,前后端实在不会关联。希望以后学成之后可以实现。
其实在上周就开通了,但是本人较笨,搞了半天没搞好,这周末终于有空重新搞起了!
Bucket的配置我只改了名称和区域,区域是因为
这里我们用到阿里云视觉智能开放平台提供的三个功能:
检测图片中车辆部件的位置以及名称。
针对常见小汽车车型,识别车辆外观受损部件及损伤类型,可识别数十种车辆部件、五大类外观损伤。(刮擦、凹陷、开裂、褶皱、穿孔)
对输入的车险图片进行分类。
<dependency>
<groupId>com.aliyun.ossgroupId>
<artifactId>aliyun-sdk-ossartifactId>
<version>3.8.0version>
dependency>
package com.example.demo;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import java.io.File;
import java.net.URL;
import java.security.SecureRandom;
import java.util.Date;
import java.lang.*;
import java.util.Scanner;
public class UploadPic {
public static String UploadPic(){
// Endpoint以杭州为例,其它Region请按实际情况填写。
String endpoint = "oss-cn-shanghai.aliyuncs.com";
// 阿里云主账号AccessKey。
String accessKeyId = "*************";
String accessKeySecret = "*************";
//本地文件名
System.out.println("请输入本地图片path:");
Scanner scanner = new Scanner(System.in);
String fileName = scanner.nextLine();
String bucketName = "auto-insurance-pic";
// 获取文件的后缀名
String suffixName = fileName.substring(fileName.lastIndexOf("."));
// 生成上传文件名
String objectName = System.currentTimeMillis() + "" + new SecureRandom().nextInt(0x0400) + suffixName;
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// 如果需要上传时设置存储类型与访问权限,请参考以下示例代码。
// ObjectMetadata metadata = new ObjectMetadata();
// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard.toString());
// metadata.setObjectAcl(CannedAccessControlList.Private);
// putObjectRequest.setMetadata(metadata);
// 上传文件。
ossClient.putObject(bucketName, objectName, new File(fileName));
// 设置URL过期时间为1小时。
Date expiration = new Date(System.currentTimeMillis() + 3600 * 1000);
// 生成以GET方法访问的签名URL,访客可以直接通过浏览器访问相关内容。
URL url = ossClient.generatePresignedUrl(bucketName, objectName, expiration);
// 关闭OSSClient。
ossClient.shutdown();
return url.toString();
}
}
运行成功!
因为属于目标检测,而根据文档中的导入指令有错,所以我来到了阿里的maven仓库下查找并选择了最新的版本进行导入。
阿里maven私有仓库服务:https://maven.aliyun.com/mvn/search
<dependency>
<groupId>com.aliyungroupId>
<artifactId>aliyun-java-sdk-coreartifactId>
<version>4.4.8version>
dependency>
<dependency>
<groupId>com.alibabagroupId>
<artifactId>fastjsonartifactId>
<version>1.2.52version>
dependency>
<dependency>
<groupId>com.aliyungroupId>
<artifactId>aliyun-java-sdk-objectdetartifactId>
<version>1.0.7version>
dependency>
package com.example.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.example.demo.UploadPic;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.objectdet.model.v20191230.*;
public class RecognizeVehicleParts {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "accessKeyId", "accessKeySecret");
IAcsClient client = new DefaultAcsClient(profile);
RecognizeVehiclePartsRequest request = new RecognizeVehiclePartsRequest();
request.setRegionId("cn-shanghai");
request.setImageURL(UploadPic.UploadPic());
try {
RecognizeVehiclePartsResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
返回值为:
{"requestId":"BBFB102D-5EAC-483F-9A94-9DA79A06E1F6","data":{"elements":[{"score":0.98788995,"type":"left_tail_light","boxes":[132,274,862,607]},{"score":0.952229,"type":"left_rear_wing","boxes":[4,162,365,750]},{"score":0.74785864,"type":"rear_bumper","boxes":[60,456,987,760]}],"originShapes":[768,1024]}}
返回部件类型为:left_tail_light 左后灯,left_rear_wing 左后翼,rear_bumper尾部保险杠
识别成功!(其实我是想识别左后灯,结果连其他两个也识别出来了!)
再来一张!!
返回值为:
{"requestId":"61E13B25-82AD-4E4C-A133-ADA281C1A4EE","data":{"elements":[{"score":0.9911305,"type":"right_front_door","boxes":[1,0,350,559]},{"score":0.9898079,"type":"right_front_tire","boxes":[335,191,727,656]},{"score":0.98655057,"type":"right_front_wing","boxes":[296,2,749,490]},{"score":0.97444427,"type":"right_doorsill","boxes":[1,497,359,651]},{"score":0.9604019,"type":"front_bumper","boxes":[671,168,779,465]}],"originShapes":[768,1024]}}
返回部件类型为:right_front_door 右前门,right_front_tire 右前轮,right_front_wing右前翼,right_doorsill右底大边,front_bumper前保险杠
识别正确!超乎预期
附文档的type说明
名字 | 英文名字 | 部件编码 | 标注编码 | 是否是34部件 | 是否计划支持 |
---|---|---|---|---|---|
前保险杠 | front_bumper |
PR01 | 11 | 是 | 是 |
后保险杠 | rear_bumper |
PR02 | 13 | 是 | 是 |
左前大灯 | left_light |
PR03 | 71 | 是 | 是 |
右前大灯 | right_light |
PR04 | 72 | 是 | 是 |
中网 | grille |
PR05 | b11 | 是 | 是 |
中网 | grille |
PR05 | B11 | 是 | 是 |
前机盖 | hood |
PR06 | 21 | 是 | 是 |
左前门 | left_front_door |
PR07 | 51 | 是 | 是 |
右前门 | right_front_door |
PR08 | 52 | 是 | 是 |
左后门 | left_rear_door |
PR09 | 53 | 是 | 是 |
右后门 | right_rear_door |
PR010 | 54 | 是 | 是 |
左前翼子板 | left_front_wing |
PR11 | 41 | 是 | 是 |
右前翼子板 | right_front_wing |
PR12 | 42 | 是 | 是 |
左后翼子板 | left_rear_wing |
PR13 | 43 | 是 | 是 |
右后翼子板 | right_rear_wing |
PR14 | 44 | 是 | 是 |
后机盖 | decklid |
PR015 | 23 | 是 | 是 |
前挡风玻璃 | front_windshield |
PR16 | 61 | 是 | 是 |
后挡风玻璃 | rear_windshield |
PR17 | 63 | 是 | 是 |
左后视镜 | left_mirror |
PR18 | 93 | 是 | 是 |
右后视镜 | right_mirror |
PR19 | 94 | 是 | 是 |
左尾灯 | left_tail_light |
PR20 | 73 | 是 | 是 |
右尾灯 | right_tail_light |
PR21 | 74 | 是 | 是 |
左雾灯 | left_foglight |
PR22 | b13 | 是 | 是 |
左雾灯 | left_foglight |
PR22 | B13 | 是 | 是 |
右雾灯 | right_foglight |
PR23 | b14 | 是 | 是 |
右雾灯 | right_foglight |
PR23 | B14 | 是 | 是 |
格栅 | grates |
PR24 | b12 | 是 | 是 |
格栅 | grates |
PR24 | B12 | 是 | 是 |
右前车窗 | right_front_window |
PR25 | 82 | 是 | 是 |
左前车窗 | left_front_window |
PR26 | 81 | 是 | 是 |
右后车窗 | right_rear_window |
PR27 | 84 | 是 | 是 |
左后车窗 | right_tail_light |
PR28 | 83 | 是 | 是 |
右底大边 | right_doorsill |
PR29 | 92 | 是 | 是 |
左底大边 | left_doorsill |
PR30 | 91 | 是 | 是 |
右前门把手 | right_front_doorknob |
PR31 | 502 | 是 | 是 |
左前门把手 | left_front_doorknob |
PR32 | 501 | 是 | 是 |
左后门把手 | left_rear_doorknob |
PR34 | 503 | 是 | 是 |
右后门把手 | right_tail_light |
PR33 | 504 | 是 | 是 |
左前轮胎 | left_front_tire |
PR3601 | 31 | 是 | 是 |
左后轮胎 | left_rear_tire |
PR3602 | 33 | 是 | 是 |
右前轮胎 | right_front_tire |
PR3603 | 32 | 是 | 是 |
右后轮胎 | right_tail_light |
PR3604 | 34 | 是 | 是 |
轮胎 | right_tail_light |
PR36 | 3 | 是 | 是 |
右前轮眉 | right_front_WheelBrow |
PR1203 | 352 | 否 | 是 |
左前轮眉 | left_front_WheelBrow |
PR1103 | 351 | 否 | 是 |
右后轮眉 | right_rear_WheelBrow |
PR1403 | 354 | 否 | 是 |
左后轮眉 | left_rear_WheelBrow |
PR1303 | 353 | 否 | 是 |
左前钢圈 | left_front_ring |
PR3501 | 316 | 否 | 是 |
左后钢圈 | left_rear_ring |
PR3502 | 336 | 否 | 是 |
右前钢圈 | right_tail_light |
PR3503 | 326 | 否 | 是 |
右后钢圈 | right_rear_ring |
PR3504 | 346 | 否 | 是 |
钢圈 | ring |
PR35 | 306 | 否 | 是 |
左前门饰条 | left_front_door_Panel |
PR0701 | 6511 | 否 | 是 |
右前门饰条 | right_front_door_Panel |
PR0801 | 6512 | 否 | 是 |
左后门饰条 | left_rear_door_Panel |
PR0901 | 6513 | 否 | 是 |
右后门饰条 | right_rear_door_Panel |
PR1001 | 6514 | 否 | 是 |
左前门亮条 | left_front_door_Wisp |
PR0701 | 6521 | 否 | 是 |
右前门亮条 | right_front_door_Wisp |
PR0801 | 6522 | 否 | 是 |
左后门亮条 | left_rear_door_Wisp |
PR0901 | 6523 | 否 | 是 |
右后门亮条 | right_rear_door_Wisp |
PR1001 | 6524 | 否 | 是 |
左前门饰板 | left_front_door_Plaque |
PR0703 | 166 | 否 | 是 |
右前门饰板 | right_front_door_Plaque |
PR0803 | 266 | 否 | 是 |
左后门饰板 | left_rear_door_Plaque |
PR0903 | 366 | 否 | 是 |
右后门饰板 | right_rear_door_Plaque |
PR1003 | 466 | 否 | 是 |
前保险杠饰条 | front_bumper_Panel |
PR0101 | 1651 | 否 | 是 |
后保险杠饰条 | rear_bumper_Panel |
PR0201 | 3651 | 否 | 是 |
前保险杠亮条 | front_bumper_Wisp |
PR0102 | 1652 | 否 | 是 |
后保险杠亮条 | rear_bumper_Wisp |
PR0202 | 3652 | 否 | 是 |
前保险杠护板 | front_bumper_Backplate |
PR0103 | 6621 | 否 | 是 |
后保险杠护板 | rear_bumper_Backplate |
PR0203 | 6623 | 否 | 是 |
前保险杠导流板 | front_bumper_Deflector |
PR0104 | 6611 | 否 | 是 |
后保险杠导流板 | rear_bumper_Deflector |
PR0204 | 6613 | 否 | 是 |
后保反光板 | BumperLight |
PR0205 | 761 | 否 | 是 |
车顶 | Roof |
待定 | 25 | 否 | 否 |
A柱 | Apillar |
待定 | 26 | 否 | 否 |
挡泥板 | Fender |
待定 | 36 | 否 | 否 |
反光镜灯 | MirrorLight |
待定 | 762 | 否 | 否 |
翼子板灯 | WingLight |
待定 | 763 | 否 | 否 |
牌照灯 | PlateLight |
待定 | 764 | 否 | 否 |
车窗三角玻璃 | TriangleWindow |
待定 | 85 | 否 | 否 |
天窗 | RoofWindow |
待定 | 86 | 否 | 否 |
字标 | WordMark |
待定 | 67 | 否 | 否 |
牵引钩盖板 | DragCover |
待定 | 681 | 否 | 否 |
喷水嘴盖板 | LightWaterCover |
待定 | 682 | 否 | 否 |
电眼 | ElectricEye |
待定 | 683 | 否 | 否 |
油箱盖 | TankCover |
待定 | 684 | 否 | 否 |
导流板(无方向) | Deflector |
待定 | 661 | 否 | 否 |
门把手(无方向) | Deflector |
待定 | 50 | 否 | 否 |
车标 | logo |
待定 | b16,B16 | 否 | 否 |
饰板(无方向) | Plaque |
待定 | 66 | 否 | 否 |
保险杠(无方向) | Roof |
待定 | 1 | 否 | 否 |
车牌 | plate |
待定 | b17,B17 | 否 | 否 |
雾灯(无方向) | foglight |
待定 | b15,B15 | 否 | 否 |
亮条(无方向) | Wisp |
待定 | 652 | 否 | 否 |
翼子板(无方向) | wing |
待定 | 4 | 否 | 否 |
饰条(无方向) | Panel |
待定 | 651 | 否 | 否 |
底大边(无方向) | doorsill |
待定 | 9 | 否 | 否 |
门(无方向) | door |
待定 | 5 | 否 | 否 |
挡风玻璃 | windshield |
待定 | 6 | 否 | 否 |
大灯(无方向) | light |
待定 | 70 | 否 | 否 |
挡泥板 | Fender |
待定 | 36 | 否 | 否 |
轮眉(无方向) | WheelBrow |
待定 | 35 | 否 | 否 |
看不出什么部件 | 无 | 待定 | 00 | 无 | 无 |
见本文二-1
package com.example.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.objectdet.model.v20191230.*;
public class RecognizeVehicleDamage {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "accessKeyId", "accessKeySecret");
IAcsClient client = new DefaultAcsClient(profile);
RecognizeVehicleDamageRequest request = new RecognizeVehicleDamageRequest();
request.setRegionId("cn-shanghai");
request.setImageURL(UploadPic.UploadPic());
try {
RecognizeVehicleDamageResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
返回值为:
{"requestId":"7FFBD390-7019-4B85-9FFA-779C912A9CEB","data":{"elements":[{"score":0.414995,"type":"1","scores":[0.414995,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"boxes":[343,390,473,542]},{"score":0.408405,"type":"1","scores":[0.408405,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"boxes":[541,442,659,545]},{"score":0.348472,"type":"1","scores":[0.348472,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"boxes":[273,293,423,400]},{"score":0.378637,"type":"2","scores":[0.0,0.378637,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"boxes":[261,26,496,142]},{"score":0.873101,"type":"5","scores":[0.0,0.0,0.0,0.0,0.873101,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"boxes":[91,4,555,267]},{"score":0.815785,"type":"6","scores":[0.0,0.0,0.0,0.0,0.0,0.815785,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"boxes":[564,270,869,441]},{"score":0.845525,"type":"8","scores":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.845525,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"boxes":[230,234,529,313]},{"score":0.411336,"type":"11","scores":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.411336,0.0,0.0,0.0,0.0],"boxes":[632,425,922,563]},{"score":0.334054,"type":"11","scores":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.334054,0.0,0.0,0.0,0.0],"boxes":[538,91,733,194]},{"score":0.333818,"type":"11","scores":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.333818,0.0,0.0,0.0,0.0],"boxes":[694,157,899,286]},{"score":0.32519,"type":"11","scores":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.32519,0.0,0.0,0.0,0.0],"boxes":[523,87,902,278]}]}}
Boxes | List | 173,178,277,259 | 部件位置框信息,形式为【左上角点x坐标,右下角点y坐标,右上角点x坐标,左下角点y坐标】。 |
---|---|---|---|
Score | Float | 0.683465 | 损伤类型对应的概率值。 |
Scores | List | 0.683465 | 对应所有15种损伤类型的损伤概率。 |
Type | String | 1 | 损伤类型id。具体Type类型如下所示。1:轻微刮擦2:重度刮擦3:轻度变形4:中度变形5:重度变形6:crack破损孔洞7:翼子板和大灯缝隙8:翼子板保险杠缝隙9:大灯轻微刮擦10:大灯重度刮擦11:大灯破损12:后视镜轻微刮擦13:后视镜玻璃破损14:后视镜脱落15:挡风玻璃破损 |
识别成功!
见本文二-1
package com.example.demo;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.objectdet.model.v20191230.*;
public class ClassifyVehicleInsurance {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "accessKeyId", "accessKeySecret");
IAcsClient client = new DefaultAcsClient(profile);
ClassifyVehicleInsuranceRequest request = new ClassifyVehicleInsuranceRequest();
request.setRegionId("cn-shanghai");
request.setImageURL(UploadPic.UploadPic());
try {
ClassifyVehicleInsuranceResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
返回值为:
{"requestId":"87BEADED-F581-4C38-9F5F-E6F8DF0A1BA5","data":{"threshold":0.0,"labels":[{"score":0.0046,"name":"others"},{"score":0.0164,"name":"detail"},{"score":0.1934,"name":"component"},{"score":0.0,"name":"vin"},{"score":8.0E-4,"name":"people"},{"score":2.0E-4,"name":"motor"},{"score":0.1439,"name":"semi-car"},{"score":0.0027,"name":"panoramic"},{"score":3.0E-4,"name":"license"},{"score":0.0169,"name":"CT-scan"},{"score":5.0E-4,"name":"truck"},{"score":0.0144,"name":"disassembly"},{"score":0.6059,"name":"scene"}]}}
Labels | Array | 输出分类结果。 | |
---|---|---|---|
Name | String | others | label名称。枚举类型。枚举值包括: others:其他 detail:细节图 component:汽车部件图 vin:汽车vin码 people:人物 motor:发动机 semi-car:半车图 panoramic:全车图 license:行驶证 CT-scan:CT-扫描 truck:卡车 disassembly:拆解件 scene:现场图 |
Score | Float | 0.0023 | 分类结果对应的概率值。 |
完成之后我会上传源码
本人是参加的达摩院特别版-视觉AI训练营第二期
训练营里面的小哥哥小姐姐说话超级好听,也有超多大佬,我超喜欢这里!