|
@@ -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) {
|