28968 il y a 6 mois
Parent
commit
bf44c9d0ce

+ 43 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/DataAugmentationController.java

@@ -22,6 +22,7 @@ import com.taais.biz.domain.bo.DataAugmentationResultBo;
 import com.taais.biz.domain.bo.VideoStableStartResultBo;
 import com.taais.biz.domain.dto.Metric;
 import com.taais.biz.domain.vo.DataAugmentationVo;
+import com.taais.biz.domain.vo.ImageUrlPair;
 import com.taais.biz.domain.vo.TaskDictDataVo;
 import com.taais.biz.domain.vo.VideoUrl;
 import com.taais.biz.service.IVideoStableService;
@@ -102,6 +103,48 @@ public class DataAugmentationController extends BaseController {
         // 如果文件名不是以数字开头,则返回一个很大的数,使其排在最后
         return -1;
     }
+
+    public static List<ImageUrlPair> generateFilePairs(Path inputPath, Path outputPath) throws IOException {
+        String localPath = TaaisConfig.getProfile();
+        Path localPathPath = Paths.get(localPath);
+
+
+        // 替换路径
+        return Files.list(inputPath)
+            .filter(Files::isRegularFile)  // 只处理文件
+            .map(path -> {
+                String fileName = path.getFileName().toString();
+                ImageUrlPair imageUrlPair = new ImageUrlPair();
+                imageUrlPair.setInputUrl(inputPath.resolve(fileName).toString().replace(localPathPath.toString(), "/profile").replace("\\", "/"));
+                imageUrlPair.setOutputUrl(outputPath.resolve(fileName).toString().replace(localPathPath.toString(), "/profile").replace("\\", "/"));
+                return imageUrlPair;
+            })
+            .collect(Collectors.toList());
+    }
+    //新接口获取图片对序列,返回支持前端PreviewCompareImages组件的数据格式
+    @GetMapping("/imageCompare/{task_id}")
+    public CommonResult<List<ImageUrlPair>> getCompareImageSeq(@PathVariable("task_id") Long taskId) throws IOException {
+        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");
+        }
+        List<ImageUrlPair> list;
+        if (!Files.exists(inputPath) || !Files.isDirectory(inputPath)) {
+            System.out.println("输入路径不存在或不是目录:" + inputPath.toString());
+            return CommonResult.fail("输入路径不存在或不是目录:" + inputPath.toString());
+        }
+        if (!Files.exists(outputPath) || !Files.isDirectory(outputPath)) {
+            System.out.println("输出路径不存在或不是目录:" + outputPath.toString());
+            return CommonResult.fail("输出路径不存在或不是目录:" + outputPath.toString());
+        }
+        list = generateFilePairs(inputPath, outputPath);
+        return  CommonResult.success(list);
+
+    }
     @GetMapping("/compare/{task_id}")
     public ResponseEntity<Map<String,List<List<String>>>> getCompareImages(@PathVariable("task_id") Long taskId) {
         try {

+ 7 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/domain/vo/ImageUrlPair.java

@@ -0,0 +1,7 @@
+package com.taais.biz.domain.vo;
+import lombok.Data;
+@Data
+public class ImageUrlPair {
+    private String inputUrl;
+    private String outputUrl;
+}