|
|
|
|
@ -238,4 +238,52 @@ public class AlgorithmService {
|
|
|
|
|
return algorithmPojo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 算法预测服务地址(yolo)
|
|
|
|
|
*/
|
|
|
|
|
private static final String PREDICT_URL = "http://127.0.0.1:8001/predict";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 调用算法服务对指定图片进行预测
|
|
|
|
|
*
|
|
|
|
|
* @param path 图片绝对路径
|
|
|
|
|
* @return 算法结果,result为1表示合格(success=true),0表示不合格
|
|
|
|
|
*/
|
|
|
|
|
public AlgorithmPojo getGoodResult(String path) {
|
|
|
|
|
AlgorithmPojo algorithmPojo = new AlgorithmPojo();
|
|
|
|
|
algorithmPojo.setPath(path);
|
|
|
|
|
String realPath = configProperties.getSavePath().getMediaPath() + path;
|
|
|
|
|
if (!configProperties.getVisualSense().getAble()) {
|
|
|
|
|
algorithmPojo.setResult(1);
|
|
|
|
|
algorithmPojo.setGoodsNumberResult(algorithmPojo.getGoodsNumber());
|
|
|
|
|
algorithmPojo.setGoodsTypeResult(algorithmPojo.getGoodsType());
|
|
|
|
|
return algorithmPojo;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
ResponseEntity<String> response = restTemplate.getForEntity(PREDICT_URL + "?path={path}", String.class, realPath);
|
|
|
|
|
String body = response.getBody();
|
|
|
|
|
log.info("算法服务返回结果:{}", body);
|
|
|
|
|
JSONObject result = JSONObject.parseObject(body);
|
|
|
|
|
if (result == null) {
|
|
|
|
|
log.error("算法服务返回结果为空,path={}", path);
|
|
|
|
|
algorithmPojo.setResult(0);
|
|
|
|
|
return algorithmPojo;
|
|
|
|
|
}
|
|
|
|
|
//success 为算法给出的判定结果:true 合格(1),false 不合格(0)
|
|
|
|
|
algorithmPojo.setResult(Boolean.TRUE.equals(result.getBoolean("success")) ? 1 : 0);
|
|
|
|
|
algorithmPojo.setGoodsNumberResult(result.getIntValue("count"));
|
|
|
|
|
algorithmPojo.setResultImage(result.getString("result_image"));
|
|
|
|
|
log.info("算法服务结果:path={}, result={}, count={}, resultImage={}",
|
|
|
|
|
result.getString("path"), algorithmPojo.getResult(),
|
|
|
|
|
algorithmPojo.getGoodsNumberResult(), algorithmPojo.getResultImage());
|
|
|
|
|
} catch (RestClientException e) {
|
|
|
|
|
log.error("未连接上算法平台" + e);
|
|
|
|
|
algorithmPojo.setResult(0);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("算法平台报错" + e);
|
|
|
|
|
algorithmPojo.setResult(0);
|
|
|
|
|
}
|
|
|
|
|
return algorithmPojo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|