|
|
|
|
@ -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<BoundingBox> 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;
|
|
|
|
|
}
|
|
|
|
|
}
|