|
@@ -1,6 +1,7 @@
|
|
|
package com.taais.biz.controller;
|
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
@@ -8,6 +9,7 @@ import java.util.Base64;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
|
import com.taais.biz.domain.DataAugmentation;
|
|
@@ -61,6 +63,15 @@ public class DataAugmentationController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private static Path getImageAtPathIdx(Path inputPath, int idx) throws IOException {
|
|
|
+ try (Stream<Path> paths = Files.list(inputPath)) {
|
|
|
+ return paths.filter(Files::isRegularFile)
|
|
|
+ .sorted()
|
|
|
+ .skip(idx)
|
|
|
+ .findFirst()
|
|
|
+ .orElseThrow(() -> new IllegalArgumentException("Index " + idx + " is out of bounds for the list of files in " + inputPath));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@GetMapping("/compare/{task_id}/{idx}")
|
|
|
public ResponseEntity<Map<String, String>> getCompareImages(@PathVariable("task_id") Long taskId, @PathVariable("idx") int idx) {
|
|
@@ -78,12 +89,18 @@ public class DataAugmentationController extends BaseController {
|
|
|
inputPath = Paths.get(dataAugmentation.getInputPath());
|
|
|
outputPath = Paths.get(dataAugmentation.getOutputPath());
|
|
|
}
|
|
|
+// inputPath = Paths.get(dataAugmentation.getInputPath());
|
|
|
+// outputPath = Paths.get(dataAugmentation.getOutputPath());
|
|
|
System.out.println("inputPath: " + inputPath.toString());
|
|
|
System.out.println("outputPath: " + outputPath.toString());
|
|
|
+ Path imagePath = getImageAtPathIdx(inputPath, idx);
|
|
|
+ String fileName = imagePath.getFileName().toString();
|
|
|
+ Path resolve = outputPath.resolve(fileName);
|
|
|
+
|
|
|
|
|
|
+ byte[] image1 = Files.readAllBytes(imagePath);
|
|
|
+ byte[] image2 = Files.readAllBytes(resolve);
|
|
|
|
|
|
- byte[] image1 = Files.readAllBytes(inputPath.resolve(String.format("%05d", idx) + ".jpg"));
|
|
|
- byte[] image2 = Files.readAllBytes(outputPath.resolve(String.format("%05d", idx) + ".jpg"));
|
|
|
|
|
|
// 将图片编码成Base64字符串
|
|
|
String base64Image1 = Base64.getEncoder().encodeToString(image1);
|