feat: 优化的票扫描接口
This commit is contained in:
@@ -109,5 +109,31 @@
|
|||||||
<artifactId>tencentcloud-sdk-java-asr</artifactId>
|
<artifactId>tencentcloud-sdk-java-asr</artifactId>
|
||||||
<version>3.1.1083</version>
|
<version>3.1.1083</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/ai.djl/api -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>ai.djl</groupId>
|
||||||
|
<artifactId>api</artifactId>
|
||||||
|
<version>0.29.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/ai.djl.pytorch/pytorch-model-zoo -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>ai.djl.pytorch</groupId>
|
||||||
|
<artifactId>pytorch-model-zoo</artifactId>
|
||||||
|
<version>0.29.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/ai.djl.pytorch/pytorch-engine -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>ai.djl.pytorch</groupId>
|
||||||
|
<artifactId>pytorch-engine</artifactId>
|
||||||
|
<version>0.29.0</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/ai.djl.pytorch/pytorch-native-auto -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>ai.djl.pytorch</groupId>
|
||||||
|
<artifactId>pytorch-native-auto</artifactId>
|
||||||
|
<version>1.9.1</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -57,10 +57,29 @@ public class NavigateController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/ticket")
|
@PostMapping("/ticket")
|
||||||
public Object scanTicket(@RequestPart MultipartFile file) throws IOException {
|
public Object scanTicket(@RequestPart MultipartFile file, @RequestParam String location) throws IOException {
|
||||||
BufferedImage image = ImageIO.read(file.getInputStream());
|
BufferedImage image = ImageIO.read(file.getInputStream());
|
||||||
Map<String, Object> map = navigateService.scanTicket(image);
|
Map<String, Object> map = navigateService.scanTicket(image);
|
||||||
return Result.ok(map);
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
if (map.containsKey("登机口")) {
|
||||||
|
String address = navigateService.deGeoCode(location);
|
||||||
|
address += map.get("登机口");
|
||||||
|
address += "登机口";
|
||||||
|
result.put("地址", address);
|
||||||
|
} else if (map.containsKey("检票口")) {
|
||||||
|
if (map.containsKey("左边车站")) {
|
||||||
|
String address = (String) map.get("左边车站");
|
||||||
|
address += map.get("检票口");
|
||||||
|
address += "检票口";
|
||||||
|
result.put("地址", address);
|
||||||
|
} else {
|
||||||
|
String address = navigateService.deGeoCode(location);
|
||||||
|
address += map.get("检票口");
|
||||||
|
address += "检票口";
|
||||||
|
result.put("地址", address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/geocode")
|
@GetMapping("/geocode")
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class NavigateService {
|
|||||||
OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile);
|
OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile);
|
||||||
SmartStructuralOCRV2Request req = new SmartStructuralOCRV2Request();
|
SmartStructuralOCRV2Request req = new SmartStructuralOCRV2Request();
|
||||||
req.setImageBase64(base64Img);
|
req.setImageBase64(base64Img);
|
||||||
String[] itemNames1 = {"登机口", "检票口"};
|
String[] itemNames1 = {"登机口", "检票口", "左边车站", "右边车站"};
|
||||||
req.setItemNames(itemNames1);
|
req.setItemNames(itemNames1);
|
||||||
resp = client.SmartStructuralOCRV2(req);
|
resp = client.SmartStructuralOCRV2(req);
|
||||||
} catch (TencentCloudSDKException e) {
|
} catch (TencentCloudSDKException e) {
|
||||||
@@ -106,4 +106,23 @@ public class NavigateService {
|
|||||||
JSONObject location = array.getJSONObject(0);
|
JSONObject location = array.getJSONObject(0);
|
||||||
return location.getString("location");
|
return location.getString("location");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String deGeoCode(String fomattedLoc) {
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("key", key);
|
||||||
|
params.put("location", fomattedLoc);
|
||||||
|
params.put("poitype", "飞机场|火车站|地铁站");
|
||||||
|
HttpResponse response = HttpRequest.get("https://restapi.amap.com/v3/geocode/regeo")
|
||||||
|
.form(params)
|
||||||
|
.execute();
|
||||||
|
String result = response.body();
|
||||||
|
response.close();
|
||||||
|
JSONObject resultObj = JSONObject.parseObject(result);
|
||||||
|
if (resultObj.getInteger("status")==0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
JSONObject reGeoCode = resultObj.getJSONObject("regeocode");
|
||||||
|
String address = reGeoCode.getString("formatted_address");
|
||||||
|
return address;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.ivmiku.tutorial.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RecogintionService {
|
||||||
|
static {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user