|
|
@@ -1,6 +1,8 @@
|
|
|
package com.fdkankan.modeldemo.utils;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -24,6 +26,7 @@ import java.io.File;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
public class ConvertUtil {
|
|
|
|
|
|
@@ -46,86 +49,27 @@ public class ConvertUtil {
|
|
|
return visibleArr;
|
|
|
}
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
-
|
|
|
- String sourcePath = "D:\\test\\";
|
|
|
- String visionPath = "D:\\test\\images\\vision.txt";
|
|
|
-
|
|
|
-// String visionStr = FileUtil.readUtf8String(visionPath);
|
|
|
-// JSONObject visionObj = JSON.parseObject(visionStr);
|
|
|
-// JSONArray array = visionObj.getJSONArray("sweepLocations");
|
|
|
-// Map<Integer, String> uuidMap = new HashMap<>();
|
|
|
-// for(int i = 0; i < array.size(); i++){
|
|
|
-// JSONObject o = (JSONObject)array.get(i);
|
|
|
-// uuidMap.put(i, o.getString("uuid"));
|
|
|
-// }
|
|
|
-//
|
|
|
-// for(int i = 0; i < array.size(); i++){
|
|
|
-// JSONObject o = (JSONObject)array.get(i);
|
|
|
-// JSONArray visibles = o.getJSONArray("visibles");
|
|
|
-// o.put("visibles", convertVisableHandler(visibles,uuidMap));
|
|
|
-//
|
|
|
-// JSONArray visibles2 = o.getJSONArray("visibles2");
|
|
|
-// o.put("visibles2", convertVisableHandler(visibles2,uuidMap));
|
|
|
-//
|
|
|
-// JSONArray visibles3 = o.getJSONArray("visibles3");
|
|
|
-// o.put("visibles3", convertVisableHandler(visibles3,uuidMap));
|
|
|
-// }
|
|
|
-//
|
|
|
-// FileUtil.writeUtf8String(JSON.toJSONString(visionObj), visionPath);
|
|
|
-
|
|
|
-
|
|
|
- //生成vison.modeldata
|
|
|
- String visionStr = FileUtil.readUtf8String(sourcePath + "images/vision.txt");
|
|
|
- JSONObject visionObj = JSON.parseObject(visionStr);
|
|
|
- JSONArray sweepLocationsArr = visionObj.getJSONArray("sweepLocations");
|
|
|
- //分割中高低点位
|
|
|
- Map<Integer, List<String>> visibleMap = new HashMap();
|
|
|
- Map<Integer, List<JSONObject>> subgroupMap = new HashMap<>();
|
|
|
- for (Object item : sweepLocationsArr) {
|
|
|
- JSONObject obj = (JSONObject) item;
|
|
|
- int subgroup = obj.getIntValue("subgroup");
|
|
|
- List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
|
|
|
- if(jsonObjects == null){
|
|
|
- jsonObjects = new ArrayList<>();
|
|
|
- subgroupMap.put(subgroup, jsonObjects);
|
|
|
- }
|
|
|
- obj.put("subgroup", 0);
|
|
|
- jsonObjects.add(obj);
|
|
|
-
|
|
|
- List<String> visible = visibleMap.get(subgroup);
|
|
|
- if(visible == null){
|
|
|
- visible = new ArrayList<>();
|
|
|
- visibleMap.put(subgroup, visible);
|
|
|
- }
|
|
|
- visible.add(obj.getString("uuid"));
|
|
|
- }
|
|
|
-
|
|
|
- for (Integer subgroup : subgroupMap.keySet()) {
|
|
|
- List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
|
|
|
- List<String> uuidList = visibleMap.get(subgroup);
|
|
|
- for (JSONObject jsonObject : jsonObjects) {
|
|
|
- String uuid = jsonObject.getString("uuid");
|
|
|
- List<String> list = Lists.newArrayList(uuidList);
|
|
|
- list.remove(uuid);
|
|
|
- jsonObject.put("visibles",list);
|
|
|
- jsonObject.put("visibles2",list);
|
|
|
- jsonObject.put("visibles3",list);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //如果是高中低场景,需要上传三份数据
|
|
|
- for (Integer subgroup : subgroupMap.keySet()) {
|
|
|
- //拆分vision.txt
|
|
|
- String visionTxtPath = sourcePath + "images/vision" + "-" + subgroup + ".txt";
|
|
|
- String visionmodeldataPath = sourcePath + "images/visionmodeldata" + "-" + subgroup + ".txt";
|
|
|
- JSONObject visionTxtJson = new JSONObject();
|
|
|
- visionTxtJson.put("sweepLocations", subgroupMap.get(subgroup));
|
|
|
- FileUtil.writeUtf8String(visionTxtJson.toJSONString(), visionTxtPath);
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldata(visionTxtPath, visionmodeldataPath);
|
|
|
+ String test = "D:\\test\\111.json";
|
|
|
+ if(FileUtil.exist(test)){
|
|
|
+ String extinguisherStr = FileUtil.readUtf8String(test);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(extinguisherStr);
|
|
|
+ JSONArray imgBoxsList = jsonObject.getJSONArray("imgBoxsList");
|
|
|
+ boolean existExtinguisher = imgBoxsList.stream().anyMatch(box -> {
|
|
|
+ JSONObject boxObj = (JSONObject) box;
|
|
|
+ JSONArray shapes = boxObj.getJSONArray("shapes");
|
|
|
+ return shapes.stream().anyMatch(shape -> {
|
|
|
+ JSONObject shapeObj = (JSONObject) shape;
|
|
|
+ if ("1111".equals(shapeObj.getString("category"))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ System.out.println(existExtinguisher);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> convert(String sourcePath, String num) throws Exception {
|
|
|
+ public Map<String, String> convert(String sourcePath, String num, String stationCode, Date upTime) throws Exception {
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
String dataViewPath = String.format(Constant.DATA_VIEW_PATH, num);
|
|
|
@@ -188,6 +132,9 @@ public class ConvertUtil {
|
|
|
CreateObjUtil.convertTxtToDam( obj2TxtPath + File.separator + "results" +File.separator+"modeldata.txt", damPath);
|
|
|
map.put(damKey, damPath);
|
|
|
|
|
|
+ //识别灭火器
|
|
|
+ Integer extinguisher = this.getExtinguisher(num, sourcePath, map);
|
|
|
+
|
|
|
//复制文件
|
|
|
JSONObject standarFloor = null;
|
|
|
Integer maxWallNum = 0;
|
|
|
@@ -297,7 +244,7 @@ public class ConvertUtil {
|
|
|
|
|
|
|
|
|
//生成场景标题
|
|
|
- String title = this.getTitle(num, sourcePath);
|
|
|
+ JSONObject sceneBashInfo = this.getSceneBashInfo(num, sourcePath);
|
|
|
|
|
|
//如果是高中低场景,需要上传三份数据
|
|
|
for (Integer subgroup : subgroupMap.keySet()) {
|
|
|
@@ -320,7 +267,7 @@ public class ConvertUtil {
|
|
|
|
|
|
//生成scene.json
|
|
|
String sceneJsonPath = sourcePath + "data/scene" + "-" + subgroup + ".json";
|
|
|
- SceneJsonBean sceneJsonBean = this.genSceneJson(num, title, subgroup);
|
|
|
+ SceneJsonBean sceneJsonBean = this.genSceneJson(num, sceneBashInfo.getString("title"), subgroup);
|
|
|
FileUtil.writeUtf8String(JSON.toJSONString(sceneJsonBean), sceneJsonPath);
|
|
|
map.put(dataViewPath + "scene.json", sceneJsonPath);
|
|
|
|
|
|
@@ -355,7 +302,7 @@ public class ConvertUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- scene.setTitle(title);
|
|
|
+ scene.setTitle(sceneBashInfo.getString("title"));
|
|
|
scene.setNum(num);
|
|
|
scene.setFloorlogosize(100);
|
|
|
scene.setScenekind("pano");
|
|
|
@@ -364,6 +311,11 @@ public class ConvertUtil {
|
|
|
scene.setModelkind("dam");
|
|
|
scene.setFloorplanangle(0);
|
|
|
scene.setSubgroup(subgroup);
|
|
|
+ scene.setStationcode(stationCode);
|
|
|
+ scene.setShootTime(sceneBashInfo.getDate("shootTime"));
|
|
|
+ scene.setUpTime(upTime);
|
|
|
+ scene.setAlgorithmTime(new Date());
|
|
|
+ scene.setExtinguisher(extinguisher);
|
|
|
sceneService.saveOrUpdate(scene);
|
|
|
}
|
|
|
|
|
|
@@ -377,6 +329,44 @@ public class ConvertUtil {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ private Integer getExtinguisher(String num, String sourcePath, Map<String, String> map){
|
|
|
+ int extinguisher = 0;
|
|
|
+ try {
|
|
|
+ String imgViewPath = String.format(Constant.IMG_VIEW_PATH, num);
|
|
|
+ //灭火器标注识别
|
|
|
+ String imagesPath = sourcePath + "images/";
|
|
|
+ String annihilatorPath = imagesPath + "4k/";
|
|
|
+ String cmd = "bash /home/ubuntu/bin/PotreeConverter.sh tieta_det " + annihilatorPath + " /home/ubuntu/bin/model/best.onnx " + imagesPath + "extinguisher.json";
|
|
|
+ log.info("---------start extinguisher, cmd:{}", cmd);
|
|
|
+ CmdUtils.callLineSh(cmd);
|
|
|
+ log.info("---------end extinguisher, cmd:{}", cmd);
|
|
|
+ if(FileUtil.exist(imagesPath + "extinguisher.json")){
|
|
|
+ map.put(imgViewPath + "extinguisher.json", imagesPath + "extinguisher.json");
|
|
|
+
|
|
|
+ String extinguisherStr = FileUtil.readUtf8String(imagesPath + "extinguisher.json");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(extinguisherStr);
|
|
|
+ JSONArray imgBoxsList = jsonObject.getJSONArray("imgBoxsList");
|
|
|
+ boolean existExtinguisher = imgBoxsList.stream().anyMatch(box -> {
|
|
|
+ JSONObject boxObj = (JSONObject) box;
|
|
|
+ JSONArray shapes = boxObj.getJSONArray("shapes");
|
|
|
+ return shapes.stream().anyMatch(shape -> {
|
|
|
+ JSONObject shapeObj = (JSONObject) shape;
|
|
|
+ if ("extinguisher".equals(shapeObj.getString("category"))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if(existExtinguisher){
|
|
|
+ extinguisher = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("getExtinguisher fail, num{}", num, e);
|
|
|
+ }
|
|
|
+ return extinguisher;
|
|
|
+ }
|
|
|
+
|
|
|
private void uploadVisionTxt(String num, String localVisionTxtPath){
|
|
|
String key = String.format(Constant.IMG_VIEW_PATH, num) + "vision.txt";
|
|
|
List<SceneFileMapping> sceneFileMappingList = sceneFileMappingService.list(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key).eq(SceneFileMapping::getNum, num).eq(SceneFileMapping::getSubgroup, -1));
|
|
|
@@ -408,18 +398,25 @@ public class ConvertUtil {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private String getTitle(String roomId, String sourcePath){
|
|
|
+ private JSONObject getSceneBashInfo(String roomId, String sourcePath){
|
|
|
+ JSONObject info = new JSONObject();
|
|
|
String sceneJsonPath = sourcePath + "data/scene.json";
|
|
|
if(!FileUtil.exist(sceneJsonPath)){
|
|
|
- return roomId;
|
|
|
+ return info;
|
|
|
}
|
|
|
String sceneJsonStr = FileUtil.readUtf8String(sceneJsonPath);
|
|
|
JSONObject jsonObject = JSON.parseObject(sceneJsonStr);
|
|
|
String title = jsonObject.getString("title");
|
|
|
if(StrUtil.isEmpty(title)){
|
|
|
- return roomId;
|
|
|
+ title = roomId;
|
|
|
+ }
|
|
|
+ info.put("title", title);
|
|
|
+ String shootTimeStr = jsonObject.getString("shootTime");
|
|
|
+ if(StrUtil.isNotEmpty(shootTimeStr)){
|
|
|
+ info.put("shootTime", DateUtil.parse(shootTimeStr, DatePattern.NORM_DATETIME_FORMAT));
|
|
|
}
|
|
|
- return title;
|
|
|
+
|
|
|
+ return info;
|
|
|
}
|
|
|
|
|
|
public static void writeDataJson(String path){
|