阿里云车牌识别
一、导入依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.15</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
二、Utils (阿里云车牌识别购买此链接https://market.aliyun.com/products/57124001/cmapi032750.html?spm=5176.21213303.J_6704733920.7.30be3edaD8xSjO&scm=20140722.S_market%40%40API%E5%B8%82%E5%9C%BA%40%40cmapi032750._.ID_market%40%40API%E5%B8%82%E5%9C%BA%40%40cmapi032750-RL_%E8%BD%A6%E7%89%8C%E8%AF%86%E5%88%AB-OR_main-V_2-P0_0#sku=yuncode2675000001)
@RequestMapping("Park")
public String park(ParklogTable parklogTable, Model model, MultipartFile file){
//图片上传成功后,将图片的地址写到数据库
String filePath="D://img";
//获得原始图片的拓展名
String originalFileName=file.getOriginalFilename();
//封装上传文件位置的全路径
File targetFile=new File(filePath,originalFileName);
//图片路径
String chepaihaotupain=targetFile.getPath();
String chepai= Main.chepaihao(chepaihaotupain);
String chepaihao="";
JSONObject json = JSONObject.fromObject(chepai);
JSONArray content = json.getJSONArray("CAR_NUMBER_RECOGNITION_ENTITY"); // 获取CAR_NUMBER_RECOGNITION_ENTITY内容
if (content.size() > 0) {
for (int i = 0; i < content.size(); i++) {
JSONObject job = content.getJSONObject(i); // 遍历 jsonarray
chepaihao= (String) job.get("NUMBER");// 得到 每个对象中的属性值
}
}
List<ParklogTable> bycarnum = service.findBycarnum(chepaihao);
if(bycarnum.isEmpty()){
Date date=new Date();
parklogTable.setParklogParktime(date);
parklogTable.setParklogCarnum(chepaihao);
parklogTable.setParklogState(1);
List<StallTable> allyes = stallService.allyes();
if(!allyes.isEmpty()){
StallTable stallTable = allyes.get(0);
int stallid=stallTable.getStallId();
String stallname=stallTable.getStallName();
parklogTable.setParklogStallid(stallid);
parklogTable.setParklogPosition(stallname);
List<VipTable> byCarnum = vipService.findByCarnum(chepaihao);
if(byCarnum.size()>0){
parklogTable.setParklogCarlevel("vip车辆");
service.insert(parklogTable);
}else{
parklogTable.setParklogCarlevel("普通车辆");
service.insert(parklogTable);
}
stallService.updatestate(stallTable);
model.addAttribute("parkmsg","欢迎"+chepaihao+"进入停车场");
}else{
model.addAttribute("parkmsg","车位已满");
}
}else{
model.addAttribute("parkmsg","您已停车");
}
return "desk";
}
<form action="Park" method="post" enctype="multipart/form-data"> 输入车牌号: <input type="file" name="file"> <input type="submit" value="停车" class="button"> </form>