Explorar o código

feat: 电子稳相修改预览逻辑

WANGKANG hai 8 meses
pai
achega
f734bb3222

+ 1 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/constant/BizConstant.java

@@ -11,6 +11,7 @@ public class BizConstant {
     public static final String PREDICT_PATH = "predict";
     public static final String PREDICT_PATH = "predict";
 
 
     public static final String UNZIP_SUFFIX = "_unzip";
     public static final String UNZIP_SUFFIX = "_unzip";
+    public static final String STABLE_SUFFIX = "_stable";
     public static final String TO_INFRARED_SUFFIX = "_to_infrared";
     public static final String TO_INFRARED_SUFFIX = "_to_infrared";
     public static final String TRACK_SEQUENCE_SUFFIX = "_track_sequence";
     public static final String TRACK_SEQUENCE_SUFFIX = "_track_sequence";
     public static final String TARGET_DETECTION_SUFFIX = "_target_detection";
     public static final String TARGET_DETECTION_SUFFIX = "_target_detection";

+ 8 - 4
taais-modules/taais-biz/src/main/java/com/taais/biz/controller/VideoStableController.java

@@ -54,7 +54,6 @@ public class VideoStableController extends BaseController {
     }
     }
 
 
 
 
-
     @GetMapping("/compare/{task_id}/{idx}")
     @GetMapping("/compare/{task_id}/{idx}")
     public ResponseEntity<Map<String, String>> getCompareImages(@PathVariable("task_id") Long taskId, @PathVariable("idx") int idx) {
     public ResponseEntity<Map<String, String>> getCompareImages(@PathVariable("task_id") Long taskId, @PathVariable("idx") int idx) {
         try {
         try {
@@ -68,8 +67,8 @@ public class VideoStableController extends BaseController {
 //                inputPath = Paths.get("C:", videoStable.getInputPath());
 //                inputPath = Paths.get("C:", videoStable.getInputPath());
 //                outputPath = Paths.get("C:", videoStable.getOutputPath());
 //                outputPath = Paths.get("C:", videoStable.getOutputPath());
 //            } else {
 //            } else {
-                inputPath = Paths.get(videoStable.getInputPath());
-                outputPath = Paths.get(videoStable.getOutputPath());
+            inputPath = Paths.get(videoStable.getInputPath());
+            outputPath = Paths.get(videoStable.getOutputPath());
 //            }
 //            }
             System.out.println("inputPath: " + inputPath.toString());
             System.out.println("inputPath: " + inputPath.toString());
             System.out.println("outputPath: " + outputPath.toString());
             System.out.println("outputPath: " + outputPath.toString());
@@ -105,7 +104,7 @@ public class VideoStableController extends BaseController {
         return videoStableService.start(id);
         return videoStableService.start(id);
     }
     }
 
 
-        @GetMapping("/stop/{id}")
+    @GetMapping("/stop/{id}")
     public CommonResult stop(@PathVariable("id") Long id) {
     public CommonResult stop(@PathVariable("id") Long id) {
         return videoStableService.stop(id);
         return videoStableService.stop(id);
     }
     }
@@ -182,4 +181,9 @@ public class VideoStableController extends BaseController {
         }
         }
         return CommonResult.success();
         return CommonResult.success();
     }
     }
+
+    @GetMapping("/images/{ossId}")
+    public CommonResult<List<Map<String, String>>> getImages(@PathVariable("ossId") Long ossId) {
+        return CommonResult.success(videoStableService.getImages(ossId));
+    }
 }
 }

+ 3 - 0
taais-modules/taais-biz/src/main/java/com/taais/biz/service/IVideoStableService.java

@@ -1,6 +1,7 @@
 package com.taais.biz.service;
 package com.taais.biz.service;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 import com.taais.biz.domain.VideoStable;
 import com.taais.biz.domain.VideoStable;
 import com.taais.biz.domain.bo.VideoStableStartResultBo;
 import com.taais.biz.domain.bo.VideoStableStartResultBo;
@@ -72,4 +73,6 @@ public interface IVideoStableService extends IBaseService<VideoStable> {
     Object getCompareNum(Long taskId);
     Object getCompareNum(Long taskId);
 
 
     CommonResult stop(Long id);
     CommonResult stop(Long id);
+
+    List<Map<String, String>> getImages(Long ossId);
 }
 }

+ 1 - 1
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/DataSeqServiceImpl.java

@@ -253,7 +253,7 @@ public class DataSeqServiceImpl extends BaseServiceImpl<DataSeqMapper, DataSeq>
     };
     };
 
 
     // 判断文件是否为常见图片格式
     // 判断文件是否为常见图片格式
-    private static boolean isImageFile(File file) {
+    public static boolean isImageFile(File file) {
         if (file.isDirectory()) {
         if (file.isDirectory()) {
             return false;
             return false;
         }
         }

+ 65 - 11
taais-modules/taais-biz/src/main/java/com/taais/biz/service/impl/VideoStableServiceImpl.java

@@ -1,13 +1,9 @@
 package com.taais.biz.service.impl;
 package com.taais.biz.service.impl;
 
 
 import java.io.File;
 import java.io.File;
-import java.io.IOException;
 import java.nio.file.Path;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.mybatisflex.core.paginate.Page;
 import com.mybatisflex.core.paginate.Page;
@@ -29,7 +25,6 @@ import com.taais.system.domain.vo.SysOssVo;
 import com.taais.system.service.ISysOssService;
 import com.taais.system.service.ISysOssService;
 import jakarta.annotation.Resource;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FileUtils;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.CloseableHttpResponse;
@@ -38,7 +33,6 @@ import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
 import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.actuate.autoconfigure.observation.ObservationProperties;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import com.taais.biz.mapper.VideoStableMapper;
 import com.taais.biz.mapper.VideoStableMapper;
@@ -48,6 +42,7 @@ import com.taais.biz.domain.vo.VideoStableVo;
 import com.taais.biz.service.IVideoStableService;
 import com.taais.biz.service.IVideoStableService;
 
 
 import static com.taais.biz.domain.table.VideoStableTableDef.VIDEO_STABLE;
 import static com.taais.biz.domain.table.VideoStableTableDef.VIDEO_STABLE;
+import static com.taais.biz.service.impl.DataSeqServiceImpl.isImageFile;
 
 
 /**
 /**
  * 视频去抖动Service业务层处理
  * 视频去抖动Service业务层处理
@@ -222,8 +217,8 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
         String fileName_without_suffix = removeFileExtension(fileName);
         String fileName_without_suffix = removeFileExtension(fileName);
 
 
         Path path = Paths.get(resourcePath);
         Path path = Paths.get(resourcePath);
-        Path inputPath = path.resolveSibling(fileName_without_suffix + "_images");
-        Path outputPath = path.resolveSibling(fileName_without_suffix + "_stable");
+        Path inputPath = path.resolveSibling(fileName_without_suffix + BizConstant.UNZIP_SUFFIX);
+        Path outputPath = path.resolveSibling(fileName_without_suffix + BizConstant.STABLE_SUFFIX);
 
 
         makeDir(inputPath.toString());
         makeDir(inputPath.toString());
         makeDir(outputPath.toString());
         makeDir(outputPath.toString());
@@ -304,8 +299,8 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
 //            inputPath = Paths.get("C:", videoStable.getInputPath());
 //            inputPath = Paths.get("C:", videoStable.getInputPath());
 //            outputPath = Paths.get("C:", videoStable.getOutputPath());
 //            outputPath = Paths.get("C:", videoStable.getOutputPath());
 //        } else {
 //        } else {
-            inputPath = Paths.get(videoStable.getInputPath());
-            outputPath = Paths.get(videoStable.getOutputPath());
+        inputPath = Paths.get(videoStable.getInputPath());
+        outputPath = Paths.get(videoStable.getOutputPath());
 //        }
 //        }
 
 
         // 创建File对象
         // 创建File对象
@@ -340,6 +335,65 @@ public class VideoStableServiceImpl extends BaseServiceImpl<VideoStableMapper, V
         }
         }
     }
     }
 
 
+    @Override
+    public List<Map<String, String>> getImages(Long inputOdssId) {
+        // 检查input_oss_id是否存在
+        if (ObjectUtil.isNull(inputOdssId)) {
+            return null;
+        }
+        SysOssVo ossEntity = ossService.getById(inputOdssId);
+        if (ObjectUtil.isNull(ossEntity)) {
+            return null;
+        }
+
+        String filePath = ossEntity.getFileName();
+        String localPath = TaaisConfig.getProfile();
+        String resourcePath = localPath + StringUtils.substringAfter(filePath, Constants.RESOURCE_PREFIX);
+        String unzipPath = resourcePath.substring(0, resourcePath.lastIndexOf(".")) + BizConstant.UNZIP_SUFFIX;
+        String resultPath = resourcePath.substring(0, resourcePath.lastIndexOf(".")) + BizConstant.STABLE_SUFFIX;
+
+        try {
+            List<String> inputImageList = getImageUrls(ossEntity, unzipPath, BizConstant.UNZIP_SUFFIX);
+            List<String> outputImageList = getImageUrls(ossEntity, resultPath, BizConstant.STABLE_SUFFIX);
+
+            HashMap<String,String> nameToUrl1 = new HashMap<>();
+            for (String imageUrl : inputImageList) {
+                String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
+                nameToUrl1.put(name, imageUrl);
+            }
+            HashMap<String,String> nameToUrl2 = new HashMap<>();
+            for (String imageUrl : outputImageList) {
+                String name = imageUrl.substring(imageUrl.lastIndexOf("/") + 1);
+                nameToUrl2.put(name, imageUrl);
+            }
+            List<String> inputImageNames = new ArrayList<>(nameToUrl1.keySet());
+
+            inputImageNames.sort(Comparator.naturalOrder());
+
+            List<Map<String, String>> resultList = new ArrayList<>();
+            for (String inputImageName : inputImageNames) {
+                Map<String, String> map = new HashMap<>();
+                map.put("inputUrl", nameToUrl1.get(inputImageName));
+                map.put("outputUrl", nameToUrl2.get(inputImageName));
+                resultList.add(map);
+            }
+
+            return resultList;
+        } catch (Exception e) {
+            System.out.println("getImages error: " + e.getMessage());
+            return null;
+        }
+    }
+
+    public List<String> getImageUrls(SysOssVo ossEntity, String path,  String suffix) {
+        String urlPrefix = ossEntity.getUrl().substring(0, ossEntity.getUrl().lastIndexOf(".")) + suffix;
+        // 列出unzipPath下所有图片文件
+        File directory = new File(path);
+        File[] files = directory.listFiles();
+        List<String> imageList = Arrays.asList(files).stream().filter(file -> isImageFile(file)).map(file -> urlPrefix + "/" + file.getName()).toList();
+        return imageList;
+    }
+
     /**
     /**
      * 递归统计文件夹中的文件数量
      * 递归统计文件夹中的文件数量
      *
      *