|
@@ -55,6 +55,8 @@ import com.taais.biz.service.IDataAugmentationService;
|
|
|
|
|
|
import com.taais.common.core.core.page.PageResult;
|
|
import com.taais.common.core.core.page.PageResult;
|
|
|
|
|
|
|
|
+import static com.taais.biz.service.impl.ToInfraredServiceImpl.readLogContent;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 数据增强Controller
|
|
* 数据增强Controller
|
|
*
|
|
*
|
|
@@ -100,120 +102,150 @@ public class DataAugmentationController extends BaseController {
|
|
// 如果文件名不是以数字开头,则返回一个很大的数,使其排在最后
|
|
// 如果文件名不是以数字开头,则返回一个很大的数,使其排在最后
|
|
return -1;
|
|
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 {
|
|
try {
|
|
- Map<String, List<String>> images = new HashMap<>();
|
|
|
|
- ArrayList<String> stable = new ArrayList<>();
|
|
|
|
- ArrayList<String> origin = new ArrayList<>();
|
|
|
|
|
|
+
|
|
DataAugmentation dataAugmentation = dataAugmentationService.getById(taskId);
|
|
DataAugmentation dataAugmentation = dataAugmentationService.getById(taskId);
|
|
Path inputPath = Paths.get(dataAugmentation.getInputPath());
|
|
Path inputPath = Paths.get(dataAugmentation.getInputPath());
|
|
Path outputPath = Paths.get(dataAugmentation.getOutputPath());
|
|
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("inputPath: " + inputPath.toString());
|
|
// System.out.println("outputPath: " + outputPath.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)) {
|
|
if (!Files.exists(inputPath) || !Files.isDirectory(inputPath)) {
|
|
System.out.println("输入路径不存在或不是目录:" + inputPath.toString());
|
|
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);
|
|
return ResponseEntity.status(500).body(images);
|
|
}
|
|
}
|
|
if (!Files.exists(outputPath) || !Files.isDirectory(outputPath)) {
|
|
if (!Files.exists(outputPath) || !Files.isDirectory(outputPath)) {
|
|
System.out.println("输出路径不存在或不是目录:" + outputPath.toString());
|
|
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);
|
|
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)) {
|
|
// 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 {
|
|
} 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);
|
|
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
|
|
// 返回Map
|
|
return ResponseEntity.ok(images);
|
|
return ResponseEntity.ok(images);
|
|
|
|
+
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return ResponseEntity.status(500).build();
|
|
return ResponseEntity.status(500).build();
|
|
@@ -382,8 +414,9 @@ public class DataAugmentationController extends BaseController {
|
|
if (!Files.exists(path)) {
|
|
if (!Files.exists(path)) {
|
|
return CommonResult.fail( "日志文件" + filePath + "不存在!");
|
|
return CommonResult.fail( "日志文件" + filePath + "不存在!");
|
|
}
|
|
}
|
|
|
|
+
|
|
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
|
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
|
- // 读取文件内容
|
|
|
|
|
|
+
|
|
return CommonResult.success(content, "获取日志成功");
|
|
return CommonResult.success(content, "获取日志成功");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
return CommonResult.fail("日志文件" + filePath + "读取失败!");
|
|
return CommonResult.fail("日志文件" + filePath + "读取失败!");
|
|
@@ -501,7 +534,10 @@ public class DataAugmentationController extends BaseController {
|
|
// 替换路径
|
|
// 替换路径
|
|
String input = inputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
|
|
String input = inputPath.toString().replace(localPathPath.toString(), "/api/profile").replace("\\", "/");
|
|
String output = outputPath.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);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|