增加计算层高正态分布等算法
parent
df0eae62a6
commit
ea7cff14b5
@ -0,0 +1,205 @@
|
|||||||
|
package com.example.lxcameraapi.controller;
|
||||||
|
|
||||||
|
import ai.onnxruntime.OrtException;
|
||||||
|
import com.example.lxcameraapi.conf.AppConfig;
|
||||||
|
import com.example.lxcameraapi.service.IndustrialCamera.algorithm.ONNXServiceNew;
|
||||||
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.lx.LxPointCloudSaveImage;
|
||||||
|
import com.example.lxcameraapi.service.IndustrialCamera.algorithm.BoxPositionConf;
|
||||||
|
import com.example.lxcameraapi.service.IndustrialCamera.algorithm.PcdPojo;
|
||||||
|
import com.example.lxcameraapi.service.IndustrialCamera.algorithm.PointCloudProcessor;
|
||||||
|
import com.example.lxcameraapi.service.IndustrialCamera.pojo.Pojo;
|
||||||
|
import com.example.lxcameraapi.yolo.BoundingBox;
|
||||||
|
import com.example.lxcameraapi.yolo.ClassifyEntity;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.example.lxcameraapi.controller.HikController.DATE_FORMATTER;
|
||||||
|
import static com.example.lxcameraapi.controller.HikController.TIME_FORMATTER;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/yolo")
|
||||||
|
public class YoloController {
|
||||||
|
@Resource
|
||||||
|
AppConfig appConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ONNXServiceNew onnxServiceNew;
|
||||||
|
|
||||||
|
@GetMapping("/detect")
|
||||||
|
public Pojo detect(String pic,String type) throws IOException {
|
||||||
|
Pojo pojo = new Pojo();
|
||||||
|
try {
|
||||||
|
List<BoundingBox> list = onnxServiceNew.detect(pic,type);
|
||||||
|
Integer index = ONNXServiceNew.getMaxClassIndex(list);
|
||||||
|
if (appConfig.getYoloModelConfig().getModelMap().containsKey(type)){
|
||||||
|
|
||||||
|
pojo.setCode(appConfig.getYoloModelConfig().getModelMap().get(type).getNames()[index]);
|
||||||
|
}else {
|
||||||
|
pojo.setCode(appConfig.getYoloModelConfig().getNames()[index]);
|
||||||
|
}
|
||||||
|
} catch (OrtException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return pojo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/detect")
|
||||||
|
public ClassifyEntity classifyOne(String pic,String type) throws IOException {
|
||||||
|
ClassifyEntity classifyEntity = null;
|
||||||
|
try {
|
||||||
|
classifyEntity = onnxServiceNew.classifyOne(pic,type);
|
||||||
|
} catch (OrtException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return classifyEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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<AppConfig.Camera> cameras = appConfig.getLxCamera();
|
||||||
|
int i = 0;
|
||||||
|
Map<Integer, String> 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<BoxPositionConf> 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<BoxPositionConf> 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<AppConfig.Camera> cameras = appConfig.getLxCamera();
|
||||||
|
int i = 0;
|
||||||
|
Map<Integer, String> map = new HashMap();
|
||||||
|
for (AppConfig.SpecialBox specialBox:appConfig.getSpecialBox()){
|
||||||
|
if (category.equals(specialBox.getCategory())){
|
||||||
|
map.put(specialBox.getCameraId(),specialBox.getComputeConfPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!map.isEmpty()){
|
||||||
|
for (Integer cameraId:map.keySet()) {
|
||||||
|
for (AppConfig.Camera c : cameras) {
|
||||||
|
if (Objects.equals(c.getId(), cameraId)) {
|
||||||
|
// LxPointCloudSaveImage.saveImage(c.getIp(), path1);
|
||||||
|
PcdPojo pojo = new PcdPojo();
|
||||||
|
if (c.getId()==1) {
|
||||||
|
pojo.setPcd1(path1);
|
||||||
|
}else {
|
||||||
|
pojo.setPcd1(path2);
|
||||||
|
}
|
||||||
|
pojo.setConfigPath(c.getConvertConfPath());
|
||||||
|
try {
|
||||||
|
pojo.setPCDInfo(pojo);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
PointCloudProcessor pointCloudProcessor = new PointCloudProcessor();
|
||||||
|
List<BoxPositionConf> confs = pointCloudProcessor.getBoxPositionConf(map.get(c.getId()));
|
||||||
|
i += pointCloudProcessor.slicing(pojo, confs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
for (AppConfig.Camera c : cameras) {
|
||||||
|
if (streetId.equals(c.getStreetId())) {
|
||||||
|
String sn = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
PcdPojo pojo = new PcdPojo();
|
||||||
|
if (c.getId()==1) {
|
||||||
|
pojo.setPcd1(path1);
|
||||||
|
}else {
|
||||||
|
pojo.setPcd1(path2);
|
||||||
|
}
|
||||||
|
pojo.setConfigPath(c.getConvertConfPath());
|
||||||
|
try {
|
||||||
|
pojo.setPCDInfo(pojo);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
PointCloudProcessor pointCloudProcessor = new PointCloudProcessor();
|
||||||
|
List<BoxPositionConf> confs = pointCloudProcessor.getBoxPositionConf(c.getComputeConfPath());
|
||||||
|
i += pointCloudProcessor.slicing(pojo, confs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue