From bb92518d323e0e5d55630137e0bec36c2052302e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Tue, 22 Sep 2026 15:12:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/YoloController.java | 60 +++++++++++++++++++ .../service/IndustrialCamera/pojo/Pojo.java | 3 + src/main/resources/application.yml | 38 ++++++------ 3 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/example/lxcameraapi/controller/YoloController.java diff --git a/src/main/java/com/example/lxcameraapi/controller/YoloController.java b/src/main/java/com/example/lxcameraapi/controller/YoloController.java new file mode 100644 index 0000000..732b5a2 --- /dev/null +++ b/src/main/java/com/example/lxcameraapi/controller/YoloController.java @@ -0,0 +1,60 @@ +package com.example.lxcameraapi.controller; + +import com.example.lxcameraapi.conf.AppConfig; +import com.example.lxcameraapi.service.IndustrialCamera.algorithm.ONNXServiceNew; +import com.example.lxcameraapi.service.IndustrialCamera.opencv.OpencvService; +import com.example.lxcameraapi.service.IndustrialCamera.pojo.Pojo; +import com.example.lxcameraapi.service.IndustrialCamera.yolo.BoundingBox; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Slf4j +@RestController +@RequestMapping("/yolo") +public class YoloController { + + + @Resource + ONNXServiceNew onnxServiceNew; + + @Resource + OpencvService opencvService; + + @Resource + AppConfig appConfig; + /** + * 在图片左上角绘制图例(按置信度排序) + * + * @return 处理结果 + */ + @PostMapping("/detect") + public Pojo detect26(@RequestBody Pojo pojo) { + try { + List boxes = onnxServiceNew.detect26(pojo.getPic(),pojo.getType()); + String destPath = pojo.getPic()+".jpg"; + Integer index = ONNXServiceNew.getMaxClassIndex( boxes); + + + opencvService.drawBoundingBoxesOnImage(boxes, pojo.getPic(), destPath); + if (index ==-1){ + pojo.setCode("Unrecognized"); + }else if (appConfig.getYoloModelConfig().getModelMap().containsKey(pojo.getType())){ + + pojo.setCode(appConfig.getYoloModelConfig().getModelMap().get(pojo.getType()).getNames()[index]); + }else { + pojo.setCode(appConfig.getYoloModelConfig().getNames()[index]); + } + pojo.setPic(destPath); + + log.info( "绘制成功,已保存到: " + destPath);; + } catch (Exception e) { + log.error("绘制图例失败", e); + log.info( "绘制失败: " + e.getMessage()); + ; + } + return pojo; + } +} diff --git a/src/main/java/com/example/lxcameraapi/service/IndustrialCamera/pojo/Pojo.java b/src/main/java/com/example/lxcameraapi/service/IndustrialCamera/pojo/Pojo.java index bbe7a5a..b38b8ce 100644 --- a/src/main/java/com/example/lxcameraapi/service/IndustrialCamera/pojo/Pojo.java +++ b/src/main/java/com/example/lxcameraapi/service/IndustrialCamera/pojo/Pojo.java @@ -10,6 +10,9 @@ public class Pojo { private String determinePath; //结果 private Boolean result; + private String code; + private String pic; private String cameraId; + private String type; private String category; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 21adcd8..8761c47 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,24 +14,24 @@ logging: file: name: logs/lxcamera-api.log #两台相机 -lxCamera: - - id: 1 - ip: 192.168.100.82 -# 1左2右 - direction: 1 -# 图片保存路径 - # 校准文件路径 - calibratePath: "D://data/cj.json" - # 品规配置文件 - configPath: "E://go/lxCamera/conf" -# 切割配置。浅货位的配置,若切割后个数多与500个,则认为有个数 - convertConfPath: "E://pz.json" - -#两台相机 -hikCamera: - - id: 1 - ip: 192.168.100.89 - imageSize: 640 +#lxCamera: +# - id: 1 +# ip: 192.168.100.82 +## 1左2右 +# direction: 1 +## 图片保存路径 +# # 校准文件路径 +# calibratePath: "D://data/cj.json" +# # 品规配置文件 +# configPath: "E://go/lxCamera/conf" +## 切割配置。浅货位的配置,若切割后个数多与500个,则认为有个数 +# convertConfPath: "E://pz.json" +# +##两台相机 +#hikCamera: +# - id: 1 +# ip: 192.168.100.89 +# imageSize: 640 swagger: enabled: true @@ -64,7 +64,7 @@ serve: yoloModelConfig: # 模型地址 - modelPath: "E:/10/best.onnx" + modelPath: "E:/data/pcdImage/best.onnx" # 图片大小 imgSize: 1024 # 置信度