dengsixing hai 2 días
pai
achega
b2c5b0d72c

+ 1 - 1
src/main/java/com/fdkankan/contro/controller/DetectType.java

@@ -1,4 +1,4 @@
-package com.fdkankan.contro.controller;
+package com.fdkankan.contro.constant;
 
 /**
  * 用户状态

+ 7 - 7
src/main/java/com/fdkankan/contro/entity/ScenePlusExt.java

@@ -1,15 +1,12 @@
 package com.fdkankan.contro.entity;
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableLogic;
-import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.util.Date;
+import com.baomidou.mybatisplus.annotation.*;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.io.Serializable;
+import java.util.Date;
+
 /**
  * <p>
  *
@@ -188,6 +185,9 @@ public class ScenePlusExt implements Serializable {
     @TableField("is_obj")
     private int isObj;
 
+    @TableField("has_recognition")
+    private Integer hasRecognition;
+
     @TableField("orientation")
     private String orientation;
 }

+ 5 - 0
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneServiceImpl.java

@@ -157,6 +157,8 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
     private ScalingService scalingService;
     @Autowired
     private RabbitTemplate rabbitTemplate;
+    @Autowired
+    private IAiService aiService;
 
 
     @Override
@@ -577,6 +579,9 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             //容量统计
             Long space = commonService.getSpace(sceneCode);
 
+            //ai识别
+            aiService.detectScenePano(scenePlus, scenePlusExt, path);
+
             //写入数据库
             this.updateDbPlus(scenePlus.getSceneSource(), space, videosJson.toJSONString(), message.getComputeTime(),isObj,scenePlusExt);
 

+ 13 - 0
src/main/java/com/fdkankan/contro/service/IAiService.java

@@ -0,0 +1,13 @@
+package com.fdkankan.contro.service;
+
+import com.fdkankan.contro.entity.SceneMarkShape;
+import com.fdkankan.contro.entity.ScenePlus;
+import com.fdkankan.contro.entity.ScenePlusExt;
+
+public interface IAiService {
+
+    void detectScenePano(ScenePlus scenePlus, ScenePlusExt scenePlusExt, String path);
+
+    SceneMarkShape readDetectJson(String jsonPath);
+
+}

+ 142 - 0
src/main/java/com/fdkankan/contro/service/impl/AiServiceImpl.java

@@ -0,0 +1,142 @@
+package com.fdkankan.contro.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.common.constant.CommonStatus;
+import com.fdkankan.contro.constant.DetectType;
+import com.fdkankan.contro.entity.SceneMarkShape;
+import com.fdkankan.contro.entity.ScenePlus;
+import com.fdkankan.contro.entity.ScenePlusExt;
+import com.fdkankan.contro.entity.SceneShapeEnum;
+import com.fdkankan.contro.service.*;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.model.constants.UploadFilePath;
+import com.fdkankan.model.utils.ComputerUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+import java.util.List;
+
+@Slf4j
+@Service
+public class AiServiceImpl implements IAiService {
+
+    @Autowired
+    private IScenePlusService scenePlusService;
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
+    @Resource
+    private FYunFileServiceInterface fYunFileService;
+    @Autowired
+    private SceneShapeEnumService sceneShapeEnumService;
+    @Autowired
+    private ISceneMarkShapeService sceneMarkShapeService;
+
+    @Override
+    public void detectScenePano(ScenePlus scenePlus, ScenePlusExt scenePlusExt, String path) {
+        try {
+            String resultsPath = path + File.separator + "results" + File.separator;
+            String highPath = resultsPath + "high" + File.separator;
+            String aiWorkPath = highPath + "ai" + File.separator;
+            List<File> highImgs = FileUtil.loopFiles(highPath);
+            if(CollUtil.isEmpty(highImgs)){
+                return;
+            }
+
+            for (File file : highImgs) {
+                String absolutePath = file.getAbsolutePath();
+                try {
+                    String name = FileUtil.getName(absolutePath);
+                    String prefix = FileUtil.getPrefix(name);
+                    String outPath = aiWorkPath + prefix + File.separator;
+                    String detectPath = outPath + "detect.json";
+                    String cutImagesPath = outPath + "cut_images";
+                    if(!ComputerUtil.checkComputeCompleted(detectPath, 5, 200)){
+                        continue;
+                    }
+                    SceneMarkShape sceneMarkShape = readDetectJson(detectPath);
+                    if (ObjectUtil.isNotNull(sceneMarkShape)){
+                        sceneMarkShape.setNum(scenePlus.getNum());
+                        SceneMarkShape shape = sceneMarkShapeService.findByNumAndImagePathAndType(scenePlus.getNum(), sceneMarkShape.getImagePath(), DetectType.PANO.getCode());
+                        if (ObjectUtil.isNotNull(shape)){
+                            sceneMarkShape.setId(shape.getId());
+                            sceneMarkShape.setUpdateTime(new Date());
+                            sceneMarkShapeService.updateById(sceneMarkShape);
+                        }else {
+                            sceneMarkShape.setCreateTime(new Date());
+                            sceneMarkShape.setType(DetectType.PANO.getCode());
+                            sceneMarkShapeService.save(sceneMarkShape);
+                        }
+                    }
+                    if (FileUtil.exist(cutImagesPath)){
+                        //上传这个文件夹所有的文件
+                        List<File> files = FileUtil.loopFiles(cutImagesPath);
+                        String keyPath =  String.format(UploadFilePath.IMG_VIEW_PATH, scenePlus.getNum()) + "cut_images/";
+                        files.forEach(v -> fYunFileService.uploadFile(v.getAbsolutePath(),keyPath+v.getName()));
+                    }
+
+                }catch (Exception e){
+                    log.error("ai识别报错,inPath:{}", absolutePath, e);
+                }
+            }
+
+            //生成ai.json
+            List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNumAndType(scenePlus.getNum(), DetectType.PANO.getCode());
+            if(CollUtil.isNotEmpty(sceneMarkShapes)){
+                for (SceneMarkShape sceneMarkShape : sceneMarkShapes) {
+                    if (ObjectUtil.isNotEmpty(sceneMarkShape.getShapes())){
+                        for (JSONObject shape : sceneMarkShape.getShapes()) {
+                            String category = shape.getString("category");
+                            SceneShapeEnum sceneShapeEnum = sceneShapeEnumService.findByClassName(category);
+                            if (ObjectUtil.isNotNull(sceneShapeEnum)){
+                                shape.put("name",sceneShapeEnum.getName());
+                            }
+                            if (category.contains("Tag_")){
+                                shape.put("category","Tag");
+                            }
+                        }
+                    }
+                }
+
+                String ajJsonKey = String.format(UploadFilePath.IMG_VIEW_PATH, scenePlus.getNum()) + "ai.json";
+                fYunFileService.uploadFile(JSON.toJSONString(sceneMarkShapes).getBytes(StandardCharsets.UTF_8), ajJsonKey);
+
+                scenePlusExt.setHasRecognition(CommonStatus.YES.code().intValue());
+            }
+        }catch (Exception e){
+            log.error("ai识别出错,num:{}", scenePlus.getNum());
+        }
+    }
+
+    @Override
+    public SceneMarkShape readDetectJson(String jsonPath) {
+        String strings = FileUtil.readString(jsonPath, "UTF-8");
+        JSONObject bbbb = JSONObject.parseObject(strings);
+        SceneMarkShape parse = JSONObject.toJavaObject(bbbb, SceneMarkShape.class);
+        System.out.println(parse);
+        if (ObjectUtil.isNull(parse.getShapes())){
+            return null;
+        }
+        List<JSONObject> shapes = parse.getShapes();
+        for (JSONObject shape : shapes) {
+            shape.remove("name");
+            SceneShapeEnum category = sceneShapeEnumService.findByClassName(shape.getString("category"));
+            if (ObjectUtil.isNull(category)){
+                SceneShapeEnum sceneShapeEnum = new SceneShapeEnum();
+                sceneShapeEnum.setName(shape.getString("name"));
+                sceneShapeEnum.setClassName(shape.getString("category"));
+                sceneShapeEnumService.save(sceneShapeEnum);
+            }
+        }
+        return parse;
+    }
+
+}