Prechádzať zdrojové kódy

v4.14.0 增加ai识别逻辑

dengsixing 5 mesiacov pred
rodič
commit
58b0eb1e32

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

@@ -12,10 +12,10 @@ import lombok.Setter;
 
 /**
  * <p>
- * 
+ *
  * </p>
  *
- * @author 
+ * @author
  * @since 2022-03-16
  */
 @Getter
@@ -187,4 +187,9 @@ public class ScenePlusExt implements Serializable {
      */
     @TableField("is_obj")
     private int isObj;
+
+    @TableField("has_ai")
+    private Integer hasAi;
+
+
 }

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

@@ -324,6 +324,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);
 
@@ -374,9 +377,6 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             String pushToken = fdageData.getString("pushToken");
             this.pushMsgToApp(pushChannel,pushToken, cameraType, scenePlus.getTitle(), scenePlusExt.getWebSite());
 
-            //ai识别
-            aiService.detectScenePano(sceneCode, path);
-
 //            //删除计算目录
             if(CollUtil.isEmpty(notDeleteNasNumList) || !notDeleteNasNumList.contains(sceneCode)){
                 CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/"));

+ 3 - 1
src/main/java/com/fdkankan/contro/service/IAiService.java

@@ -1,10 +1,12 @@
 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(String num, String path);
+    void detectScenePano(ScenePlus scenePlus, ScenePlusExt scenePlusExt, String path);
 
     SceneMarkShape readDetectJson(String jsonPath);
 

+ 3 - 1
src/main/java/com/fdkankan/contro/service/ISceneMarkShapeService.java

@@ -4,12 +4,14 @@ package com.fdkankan.contro.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.contro.entity.SceneMarkShape;
 
+import java.util.List;
+
 /**
  * Created by Xiewj on 2021/11/23 0026 10:14
  */
 public interface ISceneMarkShapeService extends IService<SceneMarkShape> {
     SceneMarkShape findByNumAndImagePathAndType(String num, String imagePath,Integer type);
 
-    SceneMarkShape findByNumAndType(String num,Integer type);
+    List<SceneMarkShape> findByNumAndType(String num, Integer type);
 
 }

+ 23 - 5
src/main/java/com/fdkankan/contro/service/impl/AiServiceImpl.java

@@ -3,9 +3,13 @@ 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;
@@ -18,8 +22,10 @@ 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;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
@@ -37,7 +43,7 @@ public class AiServiceImpl implements IAiService {
     private ISceneMarkShapeService sceneMarkShapeService;
 
     @Override
-    public void detectScenePano(String num, String path) {
+    public void detectScenePano(ScenePlus scenePlus, ScenePlusExt scenePlusExt, String path) {
 
         String resultsPath = path + File.separator + "results" + File.separator;
         String highPath = resultsPath + "high" + File.separator;
@@ -60,8 +66,8 @@ public class AiServiceImpl implements IAiService {
                 }
                 SceneMarkShape sceneMarkShape = readDetectJson(detectPath);
                 if (ObjectUtil.isNotNull(sceneMarkShape)){
-                    sceneMarkShape.setNum(num);
-                    SceneMarkShape shape = sceneMarkShapeService.findByNumAndImagePathAndType(num, sceneMarkShape.getImagePath(), DetectType.PANO.getCode());
+                    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());
@@ -75,7 +81,7 @@ public class AiServiceImpl implements IAiService {
                 if (FileUtil.exist(cutImagesPath)){
                     //上传这个文件夹所有的文件
                     List<File> files = FileUtil.loopFiles(cutImagesPath);
-                    String keyPath =  String.format(UploadFilePath.IMG_VIEW_PATH, num) + "cut_images/";
+                    String keyPath =  String.format(UploadFilePath.IMG_VIEW_PATH, scenePlus.getNum()) + "cut_images/";
                     files.forEach(v -> fYunFileService.uploadFile(v.getAbsolutePath(),keyPath+v.getName()));
                 }
 
@@ -85,9 +91,21 @@ public class AiServiceImpl implements IAiService {
         }
 
         //生成ai.json
-        SceneMarkShape sceneMarkShapes = sceneMarkShapeService.findByNumAndType(num, DetectType.PANO.getCode());
+        List<SceneMarkShape> sceneMarkShapes = sceneMarkShapeService.findByNumAndType(scenePlus.getNum(), DetectType.PANO.getCode());
+        if(CollUtil.isNotEmpty(sceneMarkShapes)){
+            List<JSONObject> collect = sceneMarkShapes.stream().map(v -> {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("index", FileUtil.getPrefix(v.getImagePath()));
+                jsonObject.put("shapes", v.getShapes());
+                return jsonObject;
+            }).collect(Collectors.toList());
 
 
+            String ajJsonKey = String.format(UploadFilePath.IMG_VIEW_PATH, scenePlus.getNum()) + "ai.json";
+            fYunFileService.uploadFile(JSON.toJSONString(collect).getBytes(StandardCharsets.UTF_8), ajJsonKey);
+
+            scenePlusExt.setHasAi(CommonStatus.YES.code().intValue());
+        }
     }
 
     @Override

+ 4 - 2
src/main/java/com/fdkankan/contro/service/impl/SceneMarkShapeServiceImpl.java

@@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 
 /**
  * Created by Xiewj on 2021/11/23 0026 10:14
@@ -32,11 +34,11 @@ public class SceneMarkShapeServiceImpl extends ServiceImpl<MarkShapeMapper, Scen
     }
 
     @Override
-    public SceneMarkShape findByNumAndType(String num, Integer type) {
+    public List<SceneMarkShape> findByNumAndType(String num, Integer type) {
         LambdaQueryWrapper<SceneMarkShape> wrapper = Wrappers.lambdaQuery();
         wrapper.eq(SceneMarkShape::getNum,num);
         wrapper.eq(SceneMarkShape::getType,type);
-        return getOne(wrapper);
+        return this.list(wrapper);
     }