|
|
package com.example.lxcameraapi.controller;
|
|
|
|
|
|
import com.example.lxcameraapi.conf.AppConfig;
|
|
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.lx.LxCameraService;
|
|
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.lx.config.BoxCountRequest;
|
|
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.lx.config.BoxCountResponse;
|
|
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.lx.config.BoxCountResult;
|
|
|
import com.example.lxcameraapi.service.IndustrialCamera.camera.lx.config.CaptureResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 箱子数量计算控制器
|
|
|
* 提供箱子数量计算接口
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("/api/boxCount")
|
|
|
public class BoxCountController {
|
|
|
|
|
|
@Autowired
|
|
|
private LxCameraService lxCameraService;
|
|
|
@Autowired
|
|
|
private AppConfig appConfig;
|
|
|
|
|
|
/**
|
|
|
* 计算箱子数量(POST请求)
|
|
|
* POST /api/boxcount/calculate
|
|
|
* Body: JSON格式的BoxCountRequest
|
|
|
*/
|
|
|
@PostMapping("/calculate")
|
|
|
public BoxCountResponse countBoxes(@RequestBody BoxCountRequest request) {
|
|
|
|
|
|
log.info("收到箱子数量计算请求: {}", request);
|
|
|
String pcdFilePath = appConfig.getPicPath();
|
|
|
String cameraIp = appConfig.getLxCamera().isEmpty() ? null : appConfig.getLxCamera().get(0).getIp();
|
|
|
String cameraCalibratePath = appConfig.getLxCamera().isEmpty() ? null : appConfig.getLxCamera().get(0).getCalibratePath();
|
|
|
request.setCameraCalibratePath(cameraCalibratePath);
|
|
|
CaptureResult captureResult = lxCameraService.capture(cameraIp,pcdFilePath);
|
|
|
request.setPcdFilePath(captureResult.getFilePath("pointCloud"));
|
|
|
|
|
|
try {
|
|
|
BoxCountResult result = lxCameraService.countBoxes(request);
|
|
|
BoxCountResponse response = BoxCountResponse.fromResult(result);
|
|
|
response.setImagePath(captureResult.getFilePath("rgb").replace(appConfig.getPicPath(), appConfig.getPicUrl()));
|
|
|
|
|
|
log.info("箱子数量计算结果: {}", result.getSummary());
|
|
|
|
|
|
return response;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
log.error("箱子数量计算异常", e);
|
|
|
return BoxCountResponse.error("计算异常: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 计算箱子数量(GET请求)
|
|
|
* GET /api/boxcount/calculate?pcdFilePath=xxx&floorHeight=xxx&boxLength=xxx&boxWidth=xxx&boxHeight=xxx&stackType=xxx
|
|
|
*/
|
|
|
@GetMapping("/calculate")
|
|
|
public BoxCountResponse countBoxesByGet(
|
|
|
@RequestParam String pcdFilePath,
|
|
|
@RequestParam(required = false) Double floorHeight,
|
|
|
@RequestParam(required = false) Double boxLength,
|
|
|
@RequestParam(required = false) Double boxWidth,
|
|
|
@RequestParam(required = false) Double boxHeight,
|
|
|
@RequestParam(required = false) String stackType,
|
|
|
@RequestParam(required = false) Integer maxBoxesPerLayer,
|
|
|
@RequestParam(required = false) Double baseTolerance,
|
|
|
@RequestParam(required = false) Double additionalTolerancePerLevel,
|
|
|
@RequestParam(required = false) String minBounds,
|
|
|
@RequestParam(required = false) String maxBounds) {
|
|
|
|
|
|
log.info("收到箱子数量计算请求(GET): pcdFilePath={}", pcdFilePath);
|
|
|
|
|
|
// 创建请求对象
|
|
|
BoxCountRequest request = new BoxCountRequest();
|
|
|
request.setPcdFilePath(pcdFilePath);
|
|
|
request.setFloorHeight(floorHeight);
|
|
|
request.setBoxLength(boxLength);
|
|
|
request.setBoxWidth(boxWidth);
|
|
|
request.setBoxHeight(boxHeight);
|
|
|
request.setStackType(stackType);
|
|
|
request.setMaxBoxesPerLayer(maxBoxesPerLayer);
|
|
|
request.setBaseTolerance(baseTolerance);
|
|
|
request.setAdditionalTolerancePerLevel(additionalTolerancePerLevel);
|
|
|
|
|
|
// 解析边界(如果提供)
|
|
|
|
|
|
|
|
|
// 调用POST处理
|
|
|
return countBoxes(request);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|