diff --git a/web/src/main/java/com/zhehekeji/web/entity/AlgorithmPojo.java b/web/src/main/java/com/zhehekeji/web/entity/AlgorithmPojo.java index 9c900f4..24059a9 100644 --- a/web/src/main/java/com/zhehekeji/web/entity/AlgorithmPojo.java +++ b/web/src/main/java/com/zhehekeji/web/entity/AlgorithmPojo.java @@ -21,6 +21,7 @@ public class AlgorithmPojo { private Calculate calculate; private String path; private String model; + private String resultImage; public static AlgorithmPojo buildAlgorithmPojo(Street street, KsecDataInfo dataInfo) { AlgorithmPojo algorithmPojo = new AlgorithmPojo(); diff --git a/web/src/main/java/com/zhehekeji/web/service/PlcService.java b/web/src/main/java/com/zhehekeji/web/service/PlcService.java index 65a2468..264da72 100644 --- a/web/src/main/java/com/zhehekeji/web/service/PlcService.java +++ b/web/src/main/java/com/zhehekeji/web/service/PlcService.java @@ -449,6 +449,7 @@ public class PlcService { if (configProperties.getActionCheckPic()){ code = "E1" + "-" + plcCmdInfo.getEndStr(1, plcCmdInfo.getFromAround()); + algorithmService.getGoodResult(path); gyrateCameraByCode(cameraId, code); @@ -787,7 +788,7 @@ public class PlcService { OrderInfo orderInfo = new OrderInfo(street, plcCmdInfo, 1, cmdCode); Stock stock = stockMapper.getByStreetAndDirectionAndSideAndRowColumn(orderInfo.getStreetId(), plcCmdInfo.getFromDirection(), orderInfo.getSeparation(), orderInfo.getRow(), orderInfo.getColumn()); - AlgorithmPojo algorithmPojo = algorithmService.getGoodResult(street, dataInfo,path); + AlgorithmPojo algorithmPojo = algorithmService.getGoodResult(path); String paths = path; //货物使用球机扫码 diff --git a/web/src/main/java/com/zhehekeji/web/service/StreetService.java b/web/src/main/java/com/zhehekeji/web/service/StreetService.java index 5c1b503..53d698a 100644 --- a/web/src/main/java/com/zhehekeji/web/service/StreetService.java +++ b/web/src/main/java/com/zhehekeji/web/service/StreetService.java @@ -216,6 +216,7 @@ public class StreetService extends ServiceImpl { } } + public void RFIDConfig(StreetVO streetVO,Integer streetId){ Map map = new HashMap<>(); map.put("street_id",streetId); diff --git a/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java b/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java index 6154257..318c0a8 100644 --- a/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java +++ b/web/src/main/java/com/zhehekeji/web/service/algorithm/AlgorithmService.java @@ -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 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; + } + }