From 652827b38b9c672b245b0447254f400c18edef26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Wed, 1 Jul 2026 18:02:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=BF=9B=E5=85=A5=E5=BC=82=E5=9E=8B=E4=B8=AA?= =?UTF-8?q?=E6=95=B0=E8=AF=86=E5=88=AB=E4=BF=AE=E6=94=B9=202.=E5=93=81?= =?UTF-8?q?=E8=A7=84=E8=AF=86=E5=88=AB=E5=8F=AA=E8=AF=86=E5=88=AB=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=98=AF=E6=89=98=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CategoryController.java | 92 +++++++++++++++++-- .../lxcameraapi/controller/HikController.java | 30 ++++-- src/main/resources/application.yml | 19 +++- 3 files changed, 127 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/example/lxcameraapi/controller/CategoryController.java b/src/main/java/com/example/lxcameraapi/controller/CategoryController.java index 6111953..841045e 100644 --- a/src/main/java/com/example/lxcameraapi/controller/CategoryController.java +++ b/src/main/java/com/example/lxcameraapi/controller/CategoryController.java @@ -6,6 +6,7 @@ import com.example.lxcameraapi.service.IndustrialCamera.algorithm.BoxPositionCon import com.example.lxcameraapi.service.IndustrialCamera.algorithm.PcdPojo; import com.example.lxcameraapi.service.IndustrialCamera.algorithm.PointCloudProcessor; import io.swagger.models.auth.In; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -20,6 +21,7 @@ import java.util.*; import static com.example.lxcameraapi.controller.HikController.DATE_FORMATTER; import static com.example.lxcameraapi.controller.HikController.TIME_FORMATTER; +@Slf4j @RestController @RequestMapping("/category") public class CategoryController { @@ -52,25 +54,97 @@ public class CategoryController { @GetMapping("/getBoxCountByCategory") public int getBoxCountByCategory(String streetId,String category) throws IOException { + if(category.equals("20")){ + return 1; + } + String path =streetId+"\\" + LocalDate.now().format(DATE_FORMATTER) +"\\"+category+"_"+ LocalDateTime.now().format(TIME_FORMATTER) +"_"; + List cameras = appConfig.getLxCamera(); + int i = 0; + Map map = new HashMap<>(); + System.out.println(appConfig.getSpecialBox().toString()); + for (AppConfig.SpecialBox specialBox:appConfig.getSpecialBox()){ + System.out.println(category.equals(specialBox.getCategory())); + if (category.equals(specialBox.getCategory())){ + map.put(specialBox.getCameraId(),specialBox.getComputeConfPath()); + System.out.println(specialBox.getCameraId()+" "+specialBox.getComputeConfPath()); + } + } + if (!map.isEmpty()){ + log.info("map: {}", map); + System.out.println("map: "+map); + for (Integer cameraId:map.keySet()) { + for (AppConfig.Camera c : cameras) { + if (Objects.equals(c.getId(), cameraId)) { + + log.info("cameraId: {}, path: {}", cameraId, path +"_"+c.getId()+ ".pcd"); + LxPointCloudSaveImage.saveImage(c.getIp(), path +"_"+c.getId()+ ".pcd"); + PcdPojo pojo = new PcdPojo(); + pojo.setPcd1(path + "_"+c.getId()+ ".pcd"); + pojo.setConfigPath(c.getConvertConfPath()); + try { + pojo.setPCDInfo(pojo); + } catch (IOException e) { + throw new RuntimeException(e); + } + PointCloudProcessor pointCloudProcessor = new PointCloudProcessor(); + List confs = pointCloudProcessor.getBoxPositionConf(map.get(c.getId())); + i += pointCloudProcessor.slicing(pojo, confs); + } + } + } + }else { + for (AppConfig.Camera c : cameras) { + if (streetId.equals(c.getStreetId())) { + + log.info("cameraId: {}, path: {}", c.getId(), path +"_"+c.getId()+ ".pcd"); + LxPointCloudSaveImage.saveImage(c.getIp(), path +"_"+c.getId()+ ".pcd"); + PcdPojo pojo = new PcdPojo(); + pojo.setPcd1(path + "_"+c.getId()+ ".pcd"); + pojo.setConfigPath(c.getConvertConfPath()); + try { + pojo.setPCDInfo(pojo); + } catch (IOException e) { + throw new RuntimeException(e); + } + PointCloudProcessor pointCloudProcessor = new PointCloudProcessor(); + List confs = pointCloudProcessor.getBoxPositionConf(c.getComputeConfPath()); + i += pointCloudProcessor.slicing(pojo, confs); + } + } + } + + return i; + } + + + @GetMapping("/getBoxCountByCategoryTest") + public int getBoxCountByCategoryTest(String streetId,String category,String path1,String path2) throws IOException { + if(category.equals("20")){ + return 1; + } + List cameras = appConfig.getLxCamera(); int i = 0; Map map = new HashMap(); for (AppConfig.SpecialBox specialBox:appConfig.getSpecialBox()){ - if (category==specialBox.getCategory()){ + if (category.equals(specialBox.getCategory())){ map.put(specialBox.getCameraId(),specialBox.getComputeConfPath()); } } - if (map.size()>0){ + if (!map.isEmpty()){ for (Integer cameraId:map.keySet()) { for (AppConfig.Camera c : cameras) { if (Objects.equals(c.getId(), cameraId)) { - String sn = UUID.randomUUID().toString(); - LxPointCloudSaveImage.saveImage(c.getIp(), path+ sn + ".pcd"); +// LxPointCloudSaveImage.saveImage(c.getIp(), path1); PcdPojo pojo = new PcdPojo(); - pojo.setPcd1(path + sn + ".pcd"); + if (c.getId()==1) { + pojo.setPcd1(path1); + }else { + pojo.setPcd1(path2); + } pojo.setConfigPath(c.getConvertConfPath()); try { pojo.setPCDInfo(pojo); @@ -87,9 +161,13 @@ public class CategoryController { for (AppConfig.Camera c : cameras) { if (streetId.equals(c.getStreetId())) { String sn = UUID.randomUUID().toString(); - LxPointCloudSaveImage.saveImage(c.getIp(), path + sn + ".pcd"); + PcdPojo pojo = new PcdPojo(); - pojo.setPcd1(path + sn + ".pcd"); + if (c.getId()==1) { + pojo.setPcd1(path1); + }else { + pojo.setPcd1(path2); + } pojo.setConfigPath(c.getConvertConfPath()); try { pojo.setPCDInfo(pojo); diff --git a/src/main/java/com/example/lxcameraapi/controller/HikController.java b/src/main/java/com/example/lxcameraapi/controller/HikController.java index 026116a..9003934 100644 --- a/src/main/java/com/example/lxcameraapi/controller/HikController.java +++ b/src/main/java/com/example/lxcameraapi/controller/HikController.java @@ -226,6 +226,7 @@ public class HikController { @GetMapping("/distinguish") @ResponseBody public Pojo distinguishOnnx(String streetNumber,int direction, String category) throws IOException { + String picPath = appConfig.getPicPath(); String path =streetNumber+"\\" + LocalDate.now().format(DATE_FORMATTER) @@ -243,18 +244,35 @@ public class HikController { // 进行标定,保存图片 Imgcodecs.imwrite(picPath+path+".jpg", Objects.requireNonNull(img2)); +// if (category.equals("20")){ +// +// Pojo pojo = new Pojo(); +// pojo.setResult(true); +// pojo.setDeterminePath(path+".jpg"); +// return pojo; +// } boolean flag = false; try { ClassifyEntity classifyEntity = onnxServiceNew.classifyOne(picPath+path+".jpg", null); - if (classifyEntity !=null && classifyEntity.getName() !=null && classifyEntity.getName().equals(category)){ - flag = true; + if(category.equals("20") ){ + if (classifyEntity !=null && classifyEntity.getName() !=null && classifyEntity.getName().equals(category)) { + flag = true; + } }else { - for (List similar:appConfig.getSimilar()){ - if (classifyEntity !=null && classifyEntity.getName() !=null && similar.contains(classifyEntity.getName())){ - flag = true; - } + if (classifyEntity !=null && classifyEntity.getName() !=null && classifyEntity.getName().equals("box")) { + flag = true; } } + +// if (classifyEntity !=null && classifyEntity.getName() !=null && classifyEntity.getName().equals(category)){ +// flag = true; +// }else { +// for (List similar:appConfig.getSimilar()){ +// if (classifyEntity !=null && classifyEntity.getName() !=null && similar.contains(classifyEntity.getName())){ +// flag = true; +// } +// } +// } } catch (OrtException e) { throw new RuntimeException(e); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8af8f92..f31d5c4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -23,6 +23,16 @@ lxCamera: # 深度切割配置,深货位配置,若切割后个数多与500个,则认为有个数 DeepConvertConfPath: "E://pz.json" + - id: 2 + ip: 192.168.100.82 + # 1左2右 + direction: 1 + # 图片保存裁剪路径,若不指定,则不保存图片 + calibratePath: "E://pz.json" + # 切割配置。浅货位的配置,若切割后个数多与500个,则认为有个数 + convertConfPath: "E://pz.json" + # 深度切割配置,深货位配置,若切割后个数多与500个,则认为有个数 + DeepConvertConfPath: "E://pz.json" #两台相机 hikCamera: - id: 1 @@ -45,7 +55,14 @@ deleteFile: similar: - ["0473","2222"] - ["333","4444"] - +#异形 +specialBox: + # 相机id + - cameraId: 2 + # 品规 + category: 21 + # 个数地址 + computeConfPath: "E://pz.json" yoloModelConfig: # 模型地址