Răsfoiți Sursa

Merge branch 'tl-develop' into develop

allen 7 luni în urmă
părinte
comite
e4ea1098b3

+ 125 - 89
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/DataAugmentationController.java

@@ -55,6 +55,8 @@ import com.taais.biz.service.IDataAugmentationService;
 
 import com.taais.common.core.core.page.PageResult;
 
+import static com.taais.biz.service.impl.ToInfraredServiceImpl.readLogContent;
+
 /**
  * 数据增强Controller
  *
@@ -100,120 +102,150 @@ public class DataAugmentationController extends BaseController {
         // 如果文件名不是以数字开头,则返回一个很大的数,使其排在最后
         return -1;
     }
-    @GetMapping("/compare/{task_id}/{idx}")
-    public ResponseEntity<Map<String,List<String>>> getCompareImages(@PathVariable("task_id") Long taskId, @PathVariable("idx") int idx) {
+    @GetMapping("/compare/{task_id}")
+    public ResponseEntity<Map<String,List<List<String>>>> getCompareImages(@PathVariable("task_id") Long taskId) {
         try {
-            Map<String, List<String>> images = new HashMap<>();
-            ArrayList<String> stable = new ArrayList<>();
-            ArrayList<String> origin = new ArrayList<>();
+
             DataAugmentation dataAugmentation = dataAugmentationService.getById(taskId);
             Path inputPath = Paths.get(dataAugmentation.getInputPath());
             Path outputPath = Paths.get(dataAugmentation.getOutputPath());
+
+            if ("多目标跟踪".equals(dataAugmentation.getTaskType())) {
+                inputPath = inputPath.resolve("input");
+                outputPath = outputPath.resolve("output");
+            }
 //            System.out.println("inputPath: " + inputPath.toString());
 //            System.out.println("outputPath: " + outputPath.toString());
+            Map<String, List<List<String>>> images = new HashMap<>();
+            List<List<String>> stable_list = new ArrayList<>();
+            List<List<String>> origin_list = new ArrayList<>();
             if (!Files.exists(inputPath) || !Files.isDirectory(inputPath)) {
                 System.out.println("输入路径不存在或不是目录:" + inputPath.toString());
-                origin.add("输入路径不存在或不是目录:" + inputPath.toString());
-                images.put("error", origin);
+                ArrayList<String> strings = new ArrayList<>();
+                strings.add("输入路径不存在或不是目录:" + inputPath.toString());
+                origin_list.add(strings);
+                images.put("error", origin_list);
                 return ResponseEntity.status(500).body(images);
             }
             if (!Files.exists(outputPath) || !Files.isDirectory(outputPath)) {
                 System.out.println("输出路径不存在或不是目录:" + outputPath.toString());
-                origin.add("输出路径不存在或不是目录:" + outputPath.toString());
-                images.put("error", origin);
+                ArrayList<String> strings = new ArrayList<>();
+                strings.add("输出路径不存在或不是目录:" + outputPath.toString());
+                stable_list.add(strings);
+                images.put("error", stable_list);
                 return ResponseEntity.status(500).body(images);
             }
-            Path imagePath = getImageAtPathIdx(inputPath, idx);  //按照自然排序获取索引为idx的imagePath
-            List<String> outputFileList = new ArrayList<>(); //初始化结果文件list
-            List<String> inputFileList = new ArrayList<>(); //初始化输入文件list
-
-            String taskType = dataAugmentation.getTaskType();
-            //图像拼接算法、目标毁伤评估有多张输入图片,则imagePath是个目录
-            if (Files.isDirectory(imagePath)) {
+            HashMap<String, Integer> compareNum = dataAugmentationService.getCompareNum(taskId);
+            Integer integer = compareNum.get("inFileCount");
+            for (int idx = 0; idx < integer; idx++) {
+
+                ArrayList<String> stable = new ArrayList<>();
+                ArrayList<String> origin = new ArrayList<>();
+                Path imagePath = getImageAtPathIdx(inputPath, idx);  //按照自然排序获取索引为idx的imagePath
+                List<String> outputFileList = new ArrayList<>(); //初始化结果文件list
+                List<String> inputFileList = new ArrayList<>(); //初始化输入文件list
+
+                String taskType = dataAugmentation.getTaskType();
+                Path inputPath1 = null;
+                Path outputPath1 = null;
+                //图像拼接算法、目标毁伤评估有多张输入图片,则imagePath是个目录
+                if (Files.isDirectory(imagePath)) {
 //            if ("侦察图像拼接算法_sift".equals(taskType) || "侦察图像拼接算法_coordinate".equals(taskType) || "目标毁伤评估".equals(taskType)) {
-                String lastDirectoryName = imagePath.getFileName().toString();
-                inputPath = imagePath;
-                outputPath = outputPath.resolve(lastDirectoryName);  //得到算法输出的结果目录
-
-                if (Files.exists(outputPath) && Files.isDirectory(outputPath)) {
-                    Stream<Path> outFilePathStream = Files.list(outputPath);
-                    // 检查流中是否有下一个元素
-                    outputFileList = outFilePathStream
-                        .filter(Files::isRegularFile)  // 只选择常规文件(排除子目录、排除图像拼接算法_sift输入中的txt文件)
-                        .filter(path -> !path.toString().toLowerCase().endsWith(".txt")).map(path -> {
-                            return path.getFileName().toString();
-                        }).collect(Collectors.toList());
-                    if ("目标毁伤评估".equals(taskType)) {
-                        QueryWrapper queryWrapper = new QueryWrapper();
-                        queryWrapper.eq("dict_type", "biz_data_augmentation");
-                        queryWrapper.eq("dict_label", "目标毁伤评估必须输出文件名称");
-                        List<SysDictData> list = sysDictDataService.list(queryWrapper);
-                        if (list.isEmpty()) {
-                            origin.add("未在数据字典中定义目标毁伤评估必须输出文件名称");
-                            images.put("error", origin);
-                            return ResponseEntity.status(500).body(images);
-                        } else {
-                            String[] split = list.get(0).getDictValue().split(",");
-                            for (String fileName: split) {
-                                if (!outputFileList.contains(fileName)) {
-                                    origin.add("输出目录不存在结果文件:" + fileName);
-                                    images.put("error", origin);
-                                    return ResponseEntity.status(500).body(images);
+                    String lastDirectoryName = imagePath.getFileName().toString();
+                    inputPath1 = imagePath;
+                    outputPath1 = outputPath.resolve(lastDirectoryName);  //得到算法输出的结果目录
+
+                    if (Files.exists(outputPath1) && Files.isDirectory(outputPath1)) {
+                        Stream<Path> outFilePathStream = Files.list(outputPath1);
+                        // 检查流中是否有下一个元素
+                        outputFileList = outFilePathStream
+                            .filter(Files::isRegularFile)  // 只选择常规文件(排除子目录、排除图像拼接算法_sift输入中的txt文件)
+                            .filter(path -> !path.toString().toLowerCase().endsWith(".txt")).map(path -> {
+                                return path.getFileName().toString();
+                            }).collect(Collectors.toList());
+                        if ("目标毁伤评估".equals(taskType)) {
+                            QueryWrapper queryWrapper = new QueryWrapper();
+                            queryWrapper.eq("dict_type", "biz_data_augmentation");
+                            queryWrapper.eq("dict_label", "目标毁伤评估必须输出文件名称");
+                            List<SysDictData> list = sysDictDataService.list(queryWrapper);
+                            if (list.isEmpty()) {
+                                origin.add("未在数据字典中定义目标毁伤评估必须输出文件名称");
+                                origin_list.add(origin);
+                                images.put("error", origin_list);
+                                return ResponseEntity.status(500).body(images);
+                            } else {
+                                String[] split = list.get(0).getDictValue().split(",");
+                                for (String fileName: split) {
+                                    if (!outputFileList.contains(fileName)) {
+                                        stable.add("输出目录不存在结果文件:" + fileName);
+                                        stable_list.add(stable);
+                                        images.put("error", stable_list);
+                                        return ResponseEntity.status(500).body(images);
+                                    }
                                 }
                             }
+                            outputFileList.sort(Comparator.comparingInt(DataAugmentationController::extractNumber));
                         }
-                        outputFileList.sort(Comparator.comparingInt(DataAugmentationController::extractNumber));
+                    } else {
+                        System.out.println(taskType + "任务:" + dataAugmentation.getId() + "未创建结果目录!");
+                        origin.add(taskType + "任务:" + dataAugmentation.getId() + "未创建结果目录!");
+                        origin_list.add(origin);
+                        images.put("error", origin_list);
+                        return ResponseEntity.status(500).body(images);
                     }
+                    Stream<Path> inputFilePathStream = Files.list(imagePath);
+                    inputFileList = inputFilePathStream
+                        .filter(Files::isRegularFile)  // 只选择常规文件(排除子目录、排除图像拼接算法_sift输入中的txt文件)
+                        .filter(path -> !path.toString().toLowerCase().endsWith(".txt"))
+                        .filter(path -> !path.toString().toLowerCase().endsWith(".json"))
+                        .map(path -> {
+                            return path.getFileName().toString();
+                        }).collect(Collectors.toList());
                 } else {
-                    System.out.println(taskType + "任务:" + dataAugmentation.getId() + "未创建结果目录!");
-                    origin.add(taskType + "任务:" + dataAugmentation.getId() + "未创建结果目录!");
-                    images.put("error", origin);
+                    //算法输入是一对一时,输出文件名称和输入文件名称相同
+                    inputPath1 = inputPath;
+                    outputPath1 = outputPath;  //得到算法输出的结果目录
+                    String inputFileName = imagePath.getFileName().toString();
+                    inputFileList.add(inputFileName);
+                    outputFileList.add(inputFileName);
+                }
+
+                if (inputFileList.isEmpty()) {
+                    System.out.println(inputPath1.toString() + ":输入文件为空" );
+                    origin.add(inputPath1.toString() + ":输入文件为空");
+                    origin_list.add(origin);
+                    images.put("error", origin_list);
                     return ResponseEntity.status(500).body(images);
                 }
-                Stream<Path> inputFilePathStream = Files.list(imagePath);
-                inputFileList = inputFilePathStream
-                    .filter(Files::isRegularFile)  // 只选择常规文件(排除子目录、排除图像拼接算法_sift输入中的txt文件)
-                    .filter(path -> !path.toString().toLowerCase().endsWith(".txt"))
-                    .filter(path -> !path.toString().toLowerCase().endsWith(".json"))
-                    .map(path -> {
-                            return path.getFileName().toString();
-                    }).collect(Collectors.toList());
-            } else {
-                //算法输入是一对一时,输出文件名称和输入文件名称相同
-                String inputFileName = imagePath.getFileName().toString();
-                inputFileList.add(inputFileName);
-                outputFileList.add(inputFileName);
-            }
+                if (outputFileList.isEmpty()) {
+                    System.out.println(outputFileList.toString() + ":输出文件为空" );
+                    stable.add(outputFileList.toString() + ":输入文件为空");
+                    stable_list.add(origin);
+                    images.put("error", stable_list);
+                    return ResponseEntity.status(500).body(images);
+                }
+                String localPath = TaaisConfig.getProfile();
+                Path localPathPath = Paths.get(localPath);
+
+
+                for (String inputFileName: inputFileList) {
+                    Path inputFilePath = inputPath1.resolve(inputFileName);
+                    origin.add(inputFilePath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/"));
+                }
+                for (String outputFileName: outputFileList) {
+                    Path outputFilePath = outputPath1.resolve(outputFileName);
+                    stable.add(outputFilePath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/"));
+                }
+                origin_list.add(origin);
+                stable_list.add(stable);
 
-            if (inputFileList.isEmpty()) {
-                System.out.println(inputPath.toString() + ":输入文件为空" );
-                origin.add(inputPath.toString() + ":输入文件为空");
-                images.put("error", origin);
-                return ResponseEntity.status(500).body(images);
-            }
-            if (outputFileList.isEmpty()) {
-                System.out.println(outputFileList.toString() + ":输出文件为空" );
-                origin.add(outputFileList.toString() + ":输入文件为空");
-                images.put("error", origin);
-                return ResponseEntity.status(500).body(images);
-            }
-            for (String inputFileName: inputFileList) {
-                Path inputFilePath = inputPath.resolve(inputFileName);
-                origin.add(Base64.getEncoder().encodeToString(Files.readAllBytes(inputFilePath)));
-            }
-            for (String outputFileName: outputFileList) {
-                Path outputFilePath = outputPath.resolve(outputFileName);
-//                if (!Files.exists(outputFilePath)) {
-//                    System.out.println("结果文件不存在:" + outputFilePath.toString());
-//                    return ResponseEntity.status(500).build();
-//                }
-                stable.add(Base64.getEncoder().encodeToString(Files.readAllBytes(outputFilePath)));
             }
-            images.put("origin", origin);
-            images.put("stable", stable);
+            images.put("origin", origin_list);
+            images.put("stable", stable_list);
 
             // 返回Map
             return ResponseEntity.ok(images);
+
         } catch (Exception e) {
             e.printStackTrace();
             return ResponseEntity.status(500).build();
@@ -382,8 +414,9 @@ public class DataAugmentationController extends BaseController {
             if (!Files.exists(path)) {
                 return CommonResult.fail( "日志文件" + filePath + "不存在!");
             }
+
             String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
-            // 读取文件内容
+
             return CommonResult.success(content, "获取日志成功");
         } catch (Exception e) {
             return CommonResult.fail("日志文件" + filePath + "读取失败!");
@@ -501,7 +534,10 @@ public class DataAugmentationController extends BaseController {
         // 替换路径
         String input = inputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
         String output = outputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
-        return  CommonResult.success(new VideoUrl(input, output));
+        VideoUrl videoUrl = new VideoUrl();
+        videoUrl.setInput(input);
+        videoUrl.setOutput(output);
+        return  CommonResult.success(videoUrl);
     }
 
 }

+ 0 - 19
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/vo/VideoUrl.java

@@ -7,24 +7,5 @@ public class VideoUrl {
     private String input;
     private String output;
 
-    public VideoUrl(String input, String output) {
-        this.input = input;
-        this.output = output;
-    }
 
-    public String getInput() {
-        return input;
-    }
-
-    public void setInput(String input) {
-        this.input = input;
-    }
-
-    public String getOutput() {
-        return output;
-    }
-
-    public void setOutput(String output) {
-        this.output = output;
-    }
 }

+ 2 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/IDataAugmentationService.java

@@ -13,6 +13,7 @@ import com.taais.common.orm.core.service.IBaseService;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.HashMap;
 import java.util.List;
 import java.util.stream.Stream;
 
@@ -75,7 +76,7 @@ public interface IDataAugmentationService extends IBaseService<DataAugmentation>
 
     CommonResult getResult(DataAugmentationResultBo videoStableStartResultBo);
 
-    Object getCompareNum(Long taskId);
+    HashMap<String, Integer> getCompareNum(Long taskId);
 
     CommonResult stop(Long id);
 

+ 6 - 2
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataAugmentationServiceImpl.java

@@ -400,7 +400,7 @@ public class DataAugmentationServiceImpl extends BaseServiceImpl<DataAugmentatio
     }
 
     @Override
-    public HashMap<String, Object> getCompareNum(Long taskId) {
+    public HashMap<String, Integer> getCompareNum(Long taskId) {
         DataAugmentation dataAugmentation = getById(taskId);
 
         Path inputPath = null;
@@ -417,6 +417,10 @@ public class DataAugmentationServiceImpl extends BaseServiceImpl<DataAugmentatio
 
         inputPath = Paths.get(dataAugmentation.getInputPath());
         outputPath = Paths.get(dataAugmentation.getOutputPath());
+        if ("多目标跟踪".equals(dataAugmentation.getTaskType())) {
+            inputPath = inputPath.resolve("input");
+            outputPath = outputPath.resolve("output");
+        }
         // 创建File对象
         File in_directory = new File(inputPath.toString());
         File out_directory = new File(outputPath.toString());
@@ -429,7 +433,7 @@ public class DataAugmentationServiceImpl extends BaseServiceImpl<DataAugmentatio
         log.info("inFileCount -> " + in_fileCount);
         log.info("outFileCount -> " + out_fileCount);
 
-        HashMap<String, Object> map = new HashMap<>();
+        HashMap<String, Integer> map = new HashMap<>();
         map.put("inFileCount", in_fileCount);
         map.put("outFileCount", out_fileCount);
         return map;