xiewj пре 2 година
родитељ
комит
477446b27f

+ 2 - 34
src/main/java/com/fdkankan/scene/controller/SceneMarkShapeController.java

@@ -129,39 +129,7 @@ public class SceneMarkShapeController extends BaseController
     @PostMapping("/editLabel")
     public ResultData editLabel(@RequestParam(value = "num") String num,@RequestParam(value = "imgPath") String imgPath,@RequestParam("file") MultipartFile file) throws IOException {
         log.info("进入editLabel---num{},imgPath{}",num,imgPath);
-        SceneMarkShape shape = sceneMarkShapeService.findByNumAndImagePath(num, imgPath);
-        if (ObjectUtil.isNotNull(shape)){
-            String uuid = UUID.randomUUID().toString();
-            String fileName = file.getOriginalFilename();
-            String extName = cn.hutool.core.io.FileUtil.extName(fileName);
-            String tempFileName = uuid + "." + extName;
-            String srcPath = ConstantFilePath.SCENE_V4_PATH + num + "/markShapes/" + tempFileName;
-            File tempFile = new File(srcPath);
-            if(!tempFile.getParentFile().exists()){
-                tempFile.getParentFile().mkdirs();
-            }
-            file.transferTo(tempFile);
-
-            List<String> s = FileUtil.readUtf8Lines(tempFile);
-            List<JSONObject> shapeJsons=new ArrayList<>();
-            //转换labelimg标注处理的结果
-            log.info("转换labelimg标注处理的结果开始");
-            for (String s1 : s) {
-                int[] ints = ConverxyUtil.centerWh2xyxy(s1, 4096,2048);
-                String[] s2 = s1.split(" ");
-                JSONObject shapeJson=new JSONObject();
-                shapeJson.put("bbox",ints);
-                shapeJson.put("color",ConverxyUtil.getColor(s2[0]));
-                shapeJson.put("label",s1);
-                shapeJson.put("category",ConverxyUtil.getLabelVal(s2[0]));
-                shapeJson.put("score",0);
-                shapeJsons.add(shapeJson);
-            }
-            log.info("转换labelimg标注处理的结果结束,{}",shapeJsons);
-            shape.setShapes(shapeJsons);
-            return ResultData.ok(sceneMarkShapeService.updateById(shape));
-        }else {
-            return ResultData.error(ErrorCode.NOT_RECORD);
-        }
+        return sceneMarkShapeService.editLabelByFile(num, imgPath, file);
     }
+
 }

+ 3 - 0
src/main/java/com/fdkankan/scene/service/ISceneMarkShapeService.java

@@ -4,6 +4,7 @@ package com.fdkankan.scene.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.scene.entity.SceneMarkShape;
 import com.fdkankan.scene.vo.SceneMarkShapeParamVO;
+import com.fdkankan.web.response.ResultData;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
@@ -15,4 +16,6 @@ public interface ISceneMarkShapeService extends IService<SceneMarkShape> {
     void saveFileToDB(MultipartFile inPath, String num) throws IOException;
 
     SceneMarkShape findByNumAndImagePath(String num, String imagePath);
+
+    ResultData editLabelByFile(String num, String imgPath, MultipartFile file) throws IOException;
 }

+ 46 - 0
src/main/java/com/fdkankan/scene/service/impl/SceneMarkShapeServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.model.constants.ConstantFilePath;
 import com.fdkankan.scene.entity.SceneMarkShape;
 import com.fdkankan.scene.entity.ScenePlusExt;
@@ -16,13 +17,18 @@ import com.fdkankan.scene.mapper.IScenePlusExtMapper;
 import com.fdkankan.scene.mapper.MarkShapeMapper;
 import com.fdkankan.scene.service.ISceneMarkShapeService;
 import com.fdkankan.scene.service.IScenePlusExtService;
+import com.fdkankan.scene.util.ConverxyUtil;
 import com.fdkankan.scene.vo.SceneMarkShapeParamVO;
+import com.fdkankan.web.response.ResultData;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
 
 
 /**
@@ -31,6 +37,46 @@ import java.io.IOException;
 @Slf4j
 @Service
 public class SceneMarkShapeServiceImpl extends ServiceImpl<MarkShapeMapper, SceneMarkShape> implements ISceneMarkShapeService {
+    @Override
+    public ResultData editLabelByFile(String num, String imgPath, MultipartFile file) throws IOException {
+
+        SceneMarkShape shape = findByNumAndImagePath(num, imgPath);
+        if (ObjectUtil.isNotNull(shape)){
+            String uuid = UUID.randomUUID().toString();
+            String fileName = file.getOriginalFilename();
+            String extName = FileUtil.extName(fileName);
+            String tempFileName = uuid + "." + extName;
+            String srcPath = ConstantFilePath.SCENE_V4_PATH + num + "/markShapes/" + tempFileName;
+            File tempFile = new File(srcPath);
+            if(!tempFile.getParentFile().exists()){
+                tempFile.getParentFile().mkdirs();
+            }
+            file.transferTo(tempFile);
+
+            List<String> s = FileUtil.readUtf8Lines(tempFile);
+            List<JSONObject> shapeJsons=new ArrayList<>();
+            //转换labelimg标注处理的结果
+            log.info("转换labelimg标注处理的结果开始");
+            for (String s1 : s) {
+                int[] ints = ConverxyUtil.centerWh2xyxy(s1, 4096,2048);
+                String[] s2 = s1.split(" ");
+                JSONObject shapeJson=new JSONObject();
+                shapeJson.put("bbox",ints);
+                shapeJson.put("color",ConverxyUtil.getColor(s2[0]));
+                shapeJson.put("label",s1);
+                shapeJson.put("category",ConverxyUtil.getLabelVal(s2[0]));
+                shapeJson.put("score",0);
+                shapeJsons.add(shapeJson);
+            }
+            log.info("转换labelimg标注处理的结果结束,{}",shapeJsons);
+            shape.setShapes(shapeJsons);
+            shape.setReDetect(1);
+            shape.setUpdateTime(new Date());
+            return ResultData.ok(updateById(shape));
+        }else {
+            return ResultData.error(ErrorCode.NOT_RECORD);
+        }
+    }
 
     @Override
     public SceneMarkShape findByNumAndImagePath(String num, String imagePath) {