增加超时时间

异步拍照加快速度
修改请求,增加延时关灯操作
修改拍照逻辑,精简逻辑,加快速度
泸州-视觉+扫码-昆船
LAPTOP-S9HJSOEB\昊天 10 months ago
parent dbc376afd9
commit c306be50b2

@ -20,8 +20,8 @@ public class FusionDesignApplication {
// 使用RestTemplateBuilder来实例化RestTemplate对象spring默认已经注入了RestTemplateBuilder实例 // 使用RestTemplateBuilder来实例化RestTemplate对象spring默认已经注入了RestTemplateBuilder实例
@Bean @Bean
public RestTemplate restTemplate() { public RestTemplate restTemplate() {
return builder.setConnectTimeout(Duration.ofSeconds(20)) // 设置连接超时时间,单位毫秒 return builder.setConnectTimeout(Duration.ofMinutes(5)) // 设置连接超时时间,单位毫秒
.setReadTimeout(Duration.ofSeconds(20)) // 设置读取超时时间,单位 .setReadTimeout(Duration.ofMinutes(20)) // 设置读取超时时间,单位
.build(); .build();
} }
} }

@ -35,6 +35,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import static com.zhehekeji.web.service.algorithm.FeatureMatchingExample.base642Mat; import static com.zhehekeji.web.service.algorithm.FeatureMatchingExample.base642Mat;
@ -70,12 +71,26 @@ public class IndustrialCameraController {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
if(configProperties.getCameraConfig().getIndustrialCamera()!=null) { if(configProperties.getCameraConfig().getIndustrialCamera()!=null) {
for (String camera:configProperties.getCameraConfig().getIndustrialCamera()) { List<CompletableFuture<Void>> futures = new ArrayList<>();
String path = "industrialCamera/" +currentDate.format(formatter)+"/"+camera+ UUID.randomUUID() + ".jpeg"; for (String camera : configProperties.getCameraConfig().getIndustrialCamera()) {
hikSaveImage.saveImage(camera, configProperties.getSavePath().getMediaPath() + path, "sn"); String path = "industrialCamera/" + currentDate.format(formatter) + "/" + camera + UUID.randomUUID() + ".jpeg";
String fullPath = configProperties.getSavePath().getMediaPath() + path;
// 提交异步任务
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
hikSaveImage.saveImage(camera, fullPath, "sn");
synchronized (list) {
list.add(path); list.add(path);
} }
});
futures.add(future);
}
// 等待所有任务完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
return new Result<>(list); return new Result<>(list);
}else { }else {
return new Result<>(list); return new Result<>(list);
@ -186,7 +201,7 @@ public class IndustrialCameraController {
kuKou.setWmsCode(industrialCameraVo.getCode()); kuKou.setWmsCode(industrialCameraVo.getCode());
kuKou.setPath(configProperties.getSavePath().getNetPicPath()+pa+".jpg"); kuKou.setPath(configProperties.getSavePath().getNetPicPath()+pa+".jpg");
kuKouService.save(kuKou); kuKouService.save(kuKou);
serialPortExample.openLight(0); // serialPortExample.openLight(0);
return new Result<>(kuKou); return new Result<>(kuKou);
} }

@ -167,33 +167,23 @@ public class HikSaveImage implements CameraSaveUtil{
@Override @Override
public boolean saveImage(String sn, String path,String type) { public boolean saveImage(String sn, String path,String type) {
int nRet = MV_OK; int nRet = MV_OK;
ArrayList<MV_CC_DEVICE_INFO> stDeviceList;
do do
{ {
System.out.println("SDK Version " + MvCameraControl.MV_CC_GetSDKVersion()); System.out.println("SDK Version " + MvCameraControl.MV_CC_GetSDKVersion());
// Enuerate GigE and USB devices // Enuerate GigE and USB devices
try
{
stDeviceList = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE);
if (0 >= stDeviceList.size())
{
System.out.println("No devices found!");
break;
}
}
catch (CameraControlException e)
{
System.err.println("Enumrate devices failed!" + e.toString());
e.printStackTrace();
break;
}
// choose camera // choose camera
Handle hCamera = init(sn,stDeviceList,type); Handle hCamera = null;
if (handleMap.containsKey(sn) && handleMap.get(sn) != null) {
//已经获得句柄
hCamera = handleMap.get(sn);
}else {
System.out.println("未找到句柄");
}
// Create handle // Create handle

@ -89,15 +89,19 @@ public class InitService implements ApplicationRunner {
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
if (configProperties.getComConfig()!=null&& !configProperties.getComConfig().equals(""))
SerialPortManager.connectSerialPort(configProperties.getComConfig()); SerialPortManager.connectSerialPort(configProperties.getComConfig());
ConfigProperties.KSEC ksec = configProperties.getKsec(); ConfigProperties.KSEC ksec = configProperties.getKsec();
inventoryService.init(); inventoryService.init();
if (configProperties.getCameraConfig()!=null
&& configProperties.getCameraConfig().getIndustrialCamera()!=null
&& !configProperties.getCameraConfig().getIndustrialCamera().equals(""))
hikSaveImage.init(configProperties.getCameraConfig().getIndustrialCamera(),"sn"); hikSaveImage.init(configProperties.getCameraConfig().getIndustrialCamera(),"sn");
if(ksec != null&& ksec.getIp()!=null&& !ksec.getIp().equals("")){ if(ksec != null&& ksec.getIp()!=null&& !ksec.getIp().equals("")){
TaskDelayExecutor.runMp4DownloadExecutor(); TaskDelayExecutor.runMp4DownloadExecutor();
nettyServer.CreateNettyServer(configProperties.getServerPort()); // nettyServer.CreateNettyServer(configProperties.getServerPort());
//球机登录 //球机登录
List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0)); List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0));
cameras.forEach(camera -> { cameras.forEach(camera -> {

@ -522,20 +522,20 @@ public class PlcService {
} }
public boolean checkVision(KsecDataInfo dataInfo,Boolean flag){ public boolean checkVision(KsecDataInfo dataInfo,Boolean flag){
try {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");
headers.set("User-Agent", "Mozilla/5.0");
IndustrialCameraVO scTransmission = new IndustrialCameraVO(); IndustrialCameraVO scTransmission = new IndustrialCameraVO();
scTransmission.setTypeMacth(dataInfo.getTypeNum()); scTransmission.setTypeMacth(dataInfo.getTypeNum());
scTransmission.setCount(dataInfo.getQuantity()); scTransmission.setCount(dataInfo.getQuantity());
scTransmission.setCode(dataInfo.getTrayCode()); scTransmission.setCode(dataInfo.getTrayCode());
try {
HttpHeaders headers = new HttpHeaders();
headers.set("Content-Type", "application/json");
headers.set("User-Agent", "Mozilla/5.0");
// 创建 HttpEntity 对象 // 创建 HttpEntity 对象
HttpEntity<IndustrialCameraVO> entity = new HttpEntity<>(scTransmission, headers); HttpEntity<IndustrialCameraVO> entity = new HttpEntity<>(scTransmission, headers);
Map<String, ConfigProperties.Template> map = configProperties.getTemplate().stream().collect(Collectors.toMap(k->k.getCode(), v->v)); // Map<String, ConfigProperties.Template> map = configProperties.getTemplate().stream().collect(Collectors.toMap(k->k.getCode(), v->v));
// 发送 POST 请求 // 发送 POST 请求
ResponseEntity<Result<KuKou>> response = restTemplate.exchange( ResponseEntity<Result<KuKou>> response = restTemplate.exchange(
@ -567,6 +567,12 @@ public class PlcService {
} }
} catch (Exception e) { } catch (Exception e) {
log.error("3D get pcd error", e); log.error("3D get pcd error", e);
scTransmission.setWmsTrayCode(dataInfo.getTrayCode());
scTransmission.setTrayCode("");
scTransmission.setCount(0);
kuKouService.setHttp(scTransmission,flag);
return false; return false;
} }
} }

@ -66,8 +66,10 @@ public class InventoryService {
} }
public void init(){ public void init(){
if (configProperties.getCameraConfig()!=null && configProperties.getCameraConfig().getCamera3D()!=null && !configProperties.getCameraConfig().getCamera3D().equals("")) {
PointerByReference handleRef = LxPointCloudSaveImage.init(configProperties.getCameraConfig().getCamera3D()); PointerByReference handleRef = LxPointCloudSaveImage.init(configProperties.getCameraConfig().getCamera3D());
} }
}
public int match3D(String category,String path){ public int match3D(String category,String path){
//拍照 //拍照
log.info("3D拍照pcd "+path); log.info("3D拍照pcd "+path);

@ -671,10 +671,12 @@ public class PointCloudProcessor {
} }
} }
for (int h =5; h>0; h--){ for (int h =5; h>0; h--){
if (map.containsKey(h) && map.get(h).size()>500){ if (map.containsKey(h) && map.get(h).size()>1000){
double area =IntervalPolygonArea.calculateArea(map.get(h),pojo.minBounds[0],10); double area =IntervalPolygonArea.calculateArea(map.get(h),pojo.minBounds[0],10);
if (area>0){ if (area>0){
int i =(layersCount*(h-1))+(int) Math.round(area/(double) (l*w)); System.out.println("面积:"+area);
System.out.println("个数:"+area/(double) (l*w));
int i =(layersCount*(h-1))+(int) Math.min(Math.round(area/(double) (l*w)),layersCount);
return i; return i;
} }
break; break;
@ -684,9 +686,9 @@ public class PointCloudProcessor {
} }
public static void main(String[] args) { public static void main(String[] args) {
String path ="E:\\工作\\泸州测试\\2\\62de6477-2ae4-47b8-91d8-f0ca54ea4a05--192.168.40.11.pcd"; String path ="E:\\泸州\\pcd\\实际53识别出54\\58ed9ebf-6956-427d-b248-50f254d652ef--192.168.32.11.pcd";
String configPath = "E:\\工作\\泸州测试\\2\\27.json"; String configPath = "E:\\工作\\泸州测试\\24\\27.json";
String typeConfPath = "E:\\工作\\泸州测试\\2\\40014845.json"; String typeConfPath = "E:\\工作\\泸州测试\\24\\40016741.json";
List<double[]> points = readPCD(path); List<double[]> points = readPCD(path);
PcdPojo pojo = new PcdPojo(); PcdPojo pojo = new PcdPojo();
PcdPojo pcdPojo = new PcdPojo(); PcdPojo pcdPojo = new PcdPojo();

@ -13,6 +13,9 @@ import org.springframework.stereotype.Service;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -38,11 +41,31 @@ public class SerialPortExample {
public static volatile SerialPort SERIAL_PORT_OBJECT = null; public static volatile SerialPort SERIAL_PORT_OBJECT = null;
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private Future<?> lightFuture = null;
public void openLight(int i){ public void openLight(int i){
if(i==1) {
if (i == 1) {
// 如果已经有任务在运行,先取消它
if (lightFuture != null && !lightFuture.isDone()) {
lightFuture.cancel(false);
}
// 开灯
SerialPortManager.sendSerialPortData(open); SerialPortManager.sendSerialPortData(open);
}else {
// 安排30分钟后执行关灯任务
lightFuture = scheduler.schedule(() -> {
synchronized (this) {
SerialPortManager.sendSerialPortData(close);
}
}, 30, TimeUnit.MINUTES);
} else {
// 如果外部直接调用关灯,也取消定时任务
if (lightFuture != null && !lightFuture.isDone()) {
lightFuture.cancel(false);
}
SerialPortManager.sendSerialPortData(close); SerialPortManager.sendSerialPortData(close);
} }
} }

Loading…
Cancel
Save