|
@@ -0,0 +1,741 @@
|
|
|
+package com.example.demo.sony;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.example.demo.Common.CommonIT;
|
|
|
+import com.example.demo.Common.constants.Constants;
|
|
|
+import com.example.demo.Common.utils.DateUtils;
|
|
|
+import com.example.demo.Common.utils.GeneralUtils;
|
|
|
+import com.example.demo.entity.Action;
|
|
|
+import com.example.demo.entity.Frame;
|
|
|
+import com.example.demo.entity.Spgl;
|
|
|
+import com.example.demo.entity.User;
|
|
|
+import com.example.demo.form.CamParam;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @program: divingcommon
|
|
|
+ * @description: SonyUtils
|
|
|
+ * @author: Guanzi
|
|
|
+ * @created: 2021/08/10 08:51
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class SonyUtils {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是入场还是出场
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String checkInOrOut(String cam) {
|
|
|
+ if (Constants.CAM_0.equals(cam) || Constants.CAM_1.equals(cam)) {
|
|
|
+ // 10米入场,直接入库一条数据。
|
|
|
+ return "in-10";
|
|
|
+ } else if (Constants.CAM_4.equals(cam) || Constants.CAM_5.equals(cam)) {
|
|
|
+ // 3米入场,直接入库一条数据。
|
|
|
+ return "in-3";
|
|
|
+
|
|
|
+ } else if (Constants.CAM_2.equals(cam) || Constants.CAM_3.equals(cam)) {
|
|
|
+ // 10米出场,去数据库根据用户id、height、cam、开始时间查询,update。
|
|
|
+ return "out-10";
|
|
|
+ } else if (Constants.CAM_6.equals(cam) || Constants.CAM_7.equals(cam)) {
|
|
|
+ // 3米出场,去数据库根据用户id、height、cam、开始时间查询,update。
|
|
|
+ return "out-3";
|
|
|
+ }
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 海康摄像头10米入场、3米入场初始化一条视频数据通用方法。
|
|
|
+ *
|
|
|
+ * @param camParam
|
|
|
+ * @param starttime
|
|
|
+ * @param height
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Spgl inCamSignal(CamParam camParam, String starttime, String height, String userId) {
|
|
|
+ String cam = camParam.getCam();
|
|
|
+ if (Constants.CAM_0.equals(cam) || Constants.CAM_1.equals(cam)) {
|
|
|
+ // 10米入场,直接入库一条数据。
|
|
|
+ Spgl spgl = initSpgl(camParam, camParam.getGetTime(), Constants.HEIGHT_TEN, userId);
|
|
|
+ return spgl;
|
|
|
+ } else if (Constants.CAM_4.equals(cam) || Constants.CAM_5.equals(cam)) {
|
|
|
+ // 3米入场,直接入库一条数据。
|
|
|
+ Spgl spgl = initSpgl(camParam, camParam.getGetTime(), Constants.HEIGHT_THREE, userId);
|
|
|
+ return spgl;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 海康摄像头10米入场、3米出场初始化一条视频数据通用方法。
|
|
|
+ *
|
|
|
+ * @param camParam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> outCamSignal(CamParam camParam, List<User> users) {
|
|
|
+ String cam = camParam.getCam();
|
|
|
+ if (Constants.CAM_2.equals(cam) || Constants.CAM_3.equals(cam)) {
|
|
|
+ // 10米出场,去数据库根据用户id、height、cam、开始时间查询,update。
|
|
|
+ Map<String, Object> mapOne = initSelMap(camParam, Constants.CAM_0, Constants.CAM_1, Constants.HEIGHT_TEN, users);
|
|
|
+ Map<String, Object> mapTwo = initSelMap(camParam, Constants.CAM_1, Constants.CAM_1, Constants.HEIGHT_TEN, users);
|
|
|
+ Map<String, Object> resMap = new HashMap<>();
|
|
|
+ resMap.put("mapOne", mapOne);
|
|
|
+ resMap.put("mapTwo", mapTwo);
|
|
|
+ return resMap;
|
|
|
+
|
|
|
+ } else if (Constants.CAM_6.equals(cam) || Constants.CAM_7.equals(cam)) {
|
|
|
+ // 3米出场,去数据库根据用户id、height、cam、开始时间查询,update。
|
|
|
+ Map<String, Object> mapOne = initSelMap(camParam, Constants.CAM_4, Constants.CAM_5, Constants.HEIGHT_THREE, users);
|
|
|
+ Map<String, Object> mapTwo = initSelMap(camParam, Constants.CAM_5, Constants.CAM_5, Constants.HEIGHT_THREE, users);
|
|
|
+ Map<String, Object> resMap = new HashMap<>();
|
|
|
+ resMap.put("mapOne", mapOne);
|
|
|
+ resMap.put("mapTwo", mapTwo);
|
|
|
+ return resMap;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化视频数据。
|
|
|
+ *
|
|
|
+ * @param camparam
|
|
|
+ * @param starttime
|
|
|
+ * @param height
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Spgl initSpgl(CamParam camparam, String starttime, String height, String userId) {
|
|
|
+ log.info("jar camparam:{}", JSON.toJSONString(camparam));
|
|
|
+ log.info("jar starttime:{}", starttime);
|
|
|
+ log.info("jar height:{}", height);
|
|
|
+ String id = new CommonIT().findId();
|
|
|
+ String title = "跳水";
|
|
|
+ String shijian = new CommonIT().findDate();
|
|
|
+
|
|
|
+ Spgl spgl = new Spgl();
|
|
|
+ spgl.setId(id);
|
|
|
+ spgl.setTitle(title);
|
|
|
+ spgl.setShijian(shijian);
|
|
|
+ // 高度
|
|
|
+ spgl.setHeight(height);
|
|
|
+ spgl.setCam(camparam.getCam());
|
|
|
+ // spgl.setCreatetime(DateUtils.getCurrentTime());
|
|
|
+
|
|
|
+ // User user = userService.findByUsername(vt.getPsbName());
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ // todo 20210508 涉及单双人视频,故此处做修改。若是双人跳水视频,则默认取第一个人先存储,后期更新时再新增第二个人。
|
|
|
+ String psbName = camparam.getPsbName().contains(",") ?
|
|
|
+ StringUtils.substringBefore(camparam.getPsbName(), ",") : camparam.getPsbName();
|
|
|
+ map.put("user_name", psbName);
|
|
|
+ // List<User> users = userMapper.selectByMap(map);
|
|
|
+ // log.info(JSON.toJSONString(users));
|
|
|
+ if (!"0".equals(userId)) {
|
|
|
+ spgl.setYdyid(userId);
|
|
|
+ // // spgl.setYdyname(users.get(0).getName());
|
|
|
+ // // todo 20210508 设计但双人视频,故此处做修改。若是双人跳水视频,则默认取第一个人先存储,后期更新时再新增第二个人。
|
|
|
+ spgl.setYdyname(camparam.getPsbName());
|
|
|
+ }else {
|
|
|
+
|
|
|
+ }
|
|
|
+ // 此处未识别出人,默认是Unknow即国家跳水队。
|
|
|
+ spgl.setYdyname(camparam.getPsbName().equals("Unknow") ? "国家跳水队" : camparam.getPsbName());
|
|
|
+ if (starttime.equals("-1")) {
|
|
|
+ spgl.setEndtime(camparam.getGetTime());
|
|
|
+ } else {
|
|
|
+ spgl.setStarttime(camparam.getGetTime());
|
|
|
+ }
|
|
|
+ spgl.setSingleflag(camparam.getPsbName().contains(",") ? "1" : "0");
|
|
|
+ // int insertId = mapper.insert(spgl);
|
|
|
+ // if (insertId > 0) {
|
|
|
+ // return spgl;
|
|
|
+ // } else {
|
|
|
+ // return null;
|
|
|
+ // }
|
|
|
+ log.info("jarcontroller spgl:{}", JSON.toJSONString(spgl));
|
|
|
+ return spgl;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化查询条件,camTwo在此逻辑暂时不用。
|
|
|
+ *
|
|
|
+ * @param camParam
|
|
|
+ * @param camOne
|
|
|
+ * @param camTwo
|
|
|
+ * @param height
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> initSelMap(CamParam camParam, String camOne, String camTwo, String height, List<User> users) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ if (users.size() > 0 && users.get(0) != null && StringUtils.isNotEmpty(users.get(0).getUser_id())) {
|
|
|
+ map.put("ydyid", users.get(0).getUser_id());
|
|
|
+ } else {
|
|
|
+ map.put("ydyname", camParam.getPsbName());
|
|
|
+ }
|
|
|
+ map.put("camone", camOne);
|
|
|
+ // 或者1,暂时弃用,xml中此条件已注释,不影响语句。
|
|
|
+ map.put("camtwo", camTwo);
|
|
|
+ map.put("height", height);
|
|
|
+ log.info("sel map:{}", JSON.toJSONString(map));
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取人体辅助训练数据
|
|
|
+ *
|
|
|
+ * @param frameList
|
|
|
+ * @param vtime
|
|
|
+ * @param height
|
|
|
+ * @param redisResThree
|
|
|
+ * @param redisResTen
|
|
|
+ * @param spgls
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> getTrainingInfos(List<Frame> frameList, String vtime, String height, JSONObject redisResThree, JSONObject redisResTen, List<Spgl> spgls, Map<String, String> map) {
|
|
|
+ // 计算帧数
|
|
|
+ String frameNum = calFrames(vtime);
|
|
|
+ Map<String, Object> resMap = new HashMap<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(frameList)) {
|
|
|
+ /**
|
|
|
+ * 3f2169c186414a0c8bd08d540bc6a21d
|
|
|
+ * c5162cdc3dc5417994b762a3ceca4d1b
|
|
|
+ * 这2个都是昨天说的新方法,6300个float变成了索引 全部是10米的
|
|
|
+ */
|
|
|
+ // JSONObject redisResThree = JSON.parseObject(redisService.get("three-json").toString());
|
|
|
+ // JSONObject redisResTen = JSON.parseObject(redisService.get("ten-json").toString());
|
|
|
+ log.info("redisResThree size:{}", redisResThree.size());
|
|
|
+ log.info("redisResTen size:{}", redisResTen.size());
|
|
|
+ // 区分3米和10米
|
|
|
+ List<List<Float>> verTexs = new ArrayList<>();
|
|
|
+ List<List<Float>> verTexSecs = new ArrayList<>();
|
|
|
+ if ("3".equals(height)) {
|
|
|
+ verTexs = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(
|
|
|
+ // redisService.get(frame.getVertex3d()).toString()
|
|
|
+ // JSON.parseObject(redisService.get("test-json").toString()).get(frame.getVertex3d()).toString()
|
|
|
+ redisResThree.get(frame.getVertex3d()).toString()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(",")
|
|
|
+ )
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ verTexSecs = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(
|
|
|
+ frame.getVertex2d()
|
|
|
+ // JSON.parseObject(redisService.get("test-json").toString()).get(frame.getVertex3d()).toString()
|
|
|
+ // redisResThree.get(frame.getVertex2d()).toString()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(",")
|
|
|
+ )
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ verTexs = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(
|
|
|
+ // redisService.get(frame.getVertex3d()).toString()
|
|
|
+ // JSON.parseObject(redisService.get("test-json").toString()).get(frame.getVertex3d()).toString()
|
|
|
+ redisResTen.get(frame.getVertex3d()).toString()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(",")
|
|
|
+ )
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ verTexSecs = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(
|
|
|
+ // redisService.get(frame.getVertex3d()).toString()
|
|
|
+ // JSON.parseObject(redisService.get("test-json").toString()).get(frame.getVertex3d()).toString()
|
|
|
+ // redisResTen.get(frame.getVertex2d()).toString()
|
|
|
+ frame.getVertex2d()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(",")
|
|
|
+ )
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("verTexs size:{}", verTexs.size());
|
|
|
+ // 偏移量
|
|
|
+ List<List<Float>> offsets = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(frame.getOffset()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(","))
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ log.info("offsets size:{}", offsets.size());
|
|
|
+ resMap.put("verTexs", verTexs);
|
|
|
+ log.info("vertexsercs:{}", verTexSecs.size());
|
|
|
+ resMap.put("verTexSecs", verTexSecs);
|
|
|
+ // if (resMap.containsKey("verTexSecs")){
|
|
|
+ // log.info("contains...");
|
|
|
+ // }else {
|
|
|
+ // log.info("dont contains...");
|
|
|
+ // }
|
|
|
+ resMap.put("offsets", offsets);
|
|
|
+ // 根据视频id和高度查询视频列表。
|
|
|
+ // List<Spgl> spgls = spglMapper.selectList(new EntityWrapper<Spgl>()
|
|
|
+ // .eq("id",videoId)
|
|
|
+ // .eq("height",height));
|
|
|
+ log.info("sel action source spgl:{}", JSON.toJSONString(spgls));
|
|
|
+ // 新增视频本地链接和bos链接。
|
|
|
+ String localvideo = spgls.size() > 0 ? spgls.get(0).getLocalpath() : null;
|
|
|
+ String bosvideo = spgls.size() > 0 ? spgls.get(0).getVideo() : null;
|
|
|
+ // Map<String,String> map = spglService.getActionSourceBosVideo(bosvideo);
|
|
|
+ String standbybosvideo = map.containsKey("url") ? map.get("url") : null;
|
|
|
+ resMap.put("localvideo", localvideo);
|
|
|
+ resMap.put("bosvideo", standbybosvideo);
|
|
|
+ resMap.put("standbybosvideo", bosvideo);
|
|
|
+ return resMap;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 帧数、秒数计算。
|
|
|
+ *
|
|
|
+ * @param vtime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String calFrames(String vtime) {
|
|
|
+ Float frameFloat = (Float.valueOf(vtime) * 60) / 1000;
|
|
|
+ int floorNum = (int) Math.floor(frameFloat);
|
|
|
+ return String.valueOf(floorNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取关键动作数据。
|
|
|
+ *
|
|
|
+ * @param actionList
|
|
|
+ * @param redisResThree
|
|
|
+ * @param redisResTen
|
|
|
+ * @param spgls
|
|
|
+ * @param map
|
|
|
+ * @param height
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> getActionInfos(List<Action> actionList, JSONObject redisResThree, JSONObject redisResTen, List<Spgl> spgls, Map<String, String> map, String height) {
|
|
|
+ Map<String, Object> resMap = new HashMap<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(actionList)) {
|
|
|
+ log.info("redisResThree size:{}", redisResThree.size());
|
|
|
+ log.info("redisResTen size:{}", redisResTen.size());
|
|
|
+ List<List<Float>> verTexs = new ArrayList<>();
|
|
|
+ if ("3".equals(height)) {
|
|
|
+ verTexs = actionList.stream()
|
|
|
+ .sorted(Comparator.comparing(Action::getActionCode))
|
|
|
+ .map(action -> Arrays.stream(
|
|
|
+ // action.getVertex3d()
|
|
|
+ redisResThree.get(action.getVertex3d()).toString()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(","))
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ verTexs = actionList.stream()
|
|
|
+ .sorted(Comparator.comparing(Action::getActionCode))
|
|
|
+ .map(action -> Arrays.stream(
|
|
|
+ // action.getVertex3d()
|
|
|
+ redisResTen.get(action.getVertex3d()).toString()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(","))
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("verTexs size:{}", verTexs.size());
|
|
|
+ // 偏移量
|
|
|
+ List<List<Float>> offsets = actionList.stream()
|
|
|
+ .sorted(Comparator.comparing(Action::getActionCode))
|
|
|
+ .map(action -> Arrays.stream(action.getOffset()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(","))
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> localpaths = actionList.stream()
|
|
|
+ .sorted(Comparator.comparing(Action::getActionCode))
|
|
|
+ .map(action -> action.getObjPath())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // bos图片路径
|
|
|
+ List<String> bospaths = actionList.stream()
|
|
|
+ .sorted(Comparator.comparing(Action::getActionCode))
|
|
|
+ .map(action -> action.getObjBos())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ log.info("offsets size:{}", offsets.size());
|
|
|
+ resMap.put("verTexs", verTexs);
|
|
|
+ resMap.put("offsets", offsets);
|
|
|
+ resMap.put("localpaths", localpaths);
|
|
|
+ resMap.put("bospaths", bospaths);
|
|
|
+ log.info("sel action source spgl:{}", JSON.toJSONString(spgls));
|
|
|
+ // 新增视频本地链接和bos链接。
|
|
|
+ String localvideo = spgls.size() > 0 ? spgls.get(0).getLocalpath() : null;
|
|
|
+ String bosvideo = spgls.size() > 0 ? spgls.get(0).getVideo() : null;
|
|
|
+ String standbybosvideo = map.containsKey("url") ? map.get("url") : null;
|
|
|
+ resMap.put("localvideo", localvideo);
|
|
|
+ resMap.put("bosvideo", standbybosvideo);
|
|
|
+ resMap.put("standbybosvideo", bosvideo);
|
|
|
+ return resMap;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人体重建数据。
|
|
|
+ *
|
|
|
+ * @param frameList
|
|
|
+ * @param redisResThree
|
|
|
+ * @param redisResTen
|
|
|
+ * @param spgls
|
|
|
+ * @param map
|
|
|
+ * @param height
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> getVideoFrameInfos(List<Frame> frameList, JSONObject redisResThree, JSONObject redisResTen, List<Spgl> spgls, Map<String, String> map, String height) {
|
|
|
+ Map<String, Object> resMap = new HashMap<>();
|
|
|
+ if (ObjectUtils.isNotEmpty(frameList)) {
|
|
|
+ log.info("redisResThree size:{}", redisResThree.size());
|
|
|
+ log.info("redisResTen size:{}", redisResTen.size());
|
|
|
+
|
|
|
+ List<List<Float>> verTexs = new ArrayList<>();
|
|
|
+ if ("3".equals(height)) {
|
|
|
+ verTexs = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(
|
|
|
+ // redisService.get(frame.getVertex3d()).toString()
|
|
|
+ // JSON.parseObject(redisService.get("test-json").toString()).get(frame.getVertex3d()).toString()
|
|
|
+ redisResThree.get(frame.getVertex3d()).toString()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(",")
|
|
|
+ )
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ verTexs = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(
|
|
|
+ // redisService.get(frame.getVertex3d()).toString()
|
|
|
+ // JSON.parseObject(redisService.get("test-json").toString()).get(frame.getVertex3d()).toString()
|
|
|
+ redisResTen.get(frame.getVertex3d()).toString()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(",")
|
|
|
+ )
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("verTexs size:{}", verTexs.size());
|
|
|
+ // 偏移量
|
|
|
+ List<List<Float>> offsets = frameList.stream()
|
|
|
+ .sorted(Comparator.comparing(Frame::getFrameName))
|
|
|
+ .map(frame -> {
|
|
|
+ return Arrays.stream(frame.getOffset()
|
|
|
+ .replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .split(","))
|
|
|
+ .map(s -> Float.parseFloat(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ log.info("offsets size:{}", offsets.size());
|
|
|
+ resMap.put("verTexs", verTexs);
|
|
|
+ resMap.put("offsets", offsets);
|
|
|
+ // 根据视频id和高度查询视频列表。
|
|
|
+ log.info("sel action source spgl:{}", JSON.toJSONString(spgls));
|
|
|
+ // 新增视频本地链接和bos链接。
|
|
|
+ String localvideo = spgls.size() > 0 ? spgls.get(0).getLocalpath() : null;
|
|
|
+ String bosvideo = spgls.size() > 0 ? spgls.get(0).getVideo() : null;
|
|
|
+ String standbybosvideo = map.containsKey("url") ? map.get("url") : null;
|
|
|
+ resMap.put("localvideo", localvideo);
|
|
|
+ resMap.put("bosvideo", standbybosvideo);
|
|
|
+ resMap.put("standbybosvideo", bosvideo);
|
|
|
+ return resMap;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关键动作数据处理。
|
|
|
+ *
|
|
|
+ * @param tmpSpgl
|
|
|
+ * @param bosPath
|
|
|
+ * @param height
|
|
|
+ * @param fileName
|
|
|
+ * @param skeletons
|
|
|
+ * @param files
|
|
|
+ * @param offset
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public Action insertActionInfos(Spgl tmpSpgl,MultipartFile file, String name,long startTime,String height, String bosPath, String fileDate, String fileName, String skeletons, MultipartFile[] files, String offset) throws IOException {
|
|
|
+ //解析skeletons
|
|
|
+ JSONObject jsonObj = JSON.parseObject(skeletons);
|
|
|
+ Map jsonSet = jsonObj.toJavaObject(Map.class);
|
|
|
+
|
|
|
+ JSONObject jsonObjOffset = JSON.parseObject(offset);
|
|
|
+ Map jsonSetOffset = jsonObjOffset.toJavaObject(Map.class);
|
|
|
+
|
|
|
+ //获取动作总数
|
|
|
+ int actionNumber = jsonSet.size();
|
|
|
+
|
|
|
+ //存储关键动作到BOS
|
|
|
+ log.info("fileName:{}", name);
|
|
|
+ log.info("bospath:{}", bosPath);
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ String fileSize = GeneralUtils.getFileSize(file.getSize());
|
|
|
+ log.info("当前文件大小:{}", fileSize);
|
|
|
+ log.info("关键动作上传至BOS云服务器耗时:{}", DateUtils.getExcTime(startTime, endTime));
|
|
|
+
|
|
|
+ Object frameInfo = jsonSet.get(name);
|
|
|
+ Action action = new Action();
|
|
|
+ String vertex3d = frameInfo.toString();
|
|
|
+ String insertOffset = jsonObjOffset.get(name).toString();
|
|
|
+
|
|
|
+
|
|
|
+ //自增id,设为0实现自增
|
|
|
+ action.setId(0);
|
|
|
+ action.setVideoId(tmpSpgl.getId());
|
|
|
+ action.setVideoName(tmpSpgl.getVideo().substring(tmpSpgl.getVideo().lastIndexOf("/") + 1));
|
|
|
+ action.setHeight(Integer.parseInt(height));
|
|
|
+ action.setActionCode(name);
|
|
|
+ action.setActionNumber(actionNumber);
|
|
|
+ action.setVertex3d(vertex3d);
|
|
|
+ action.setOffset(insertOffset);
|
|
|
+
|
|
|
+
|
|
|
+ //保存关键动作相关信息
|
|
|
+ // String date = DateUtils.createFilesByDate();
|
|
|
+ action.setCreateTime(DateUtils.getCurrentTime());
|
|
|
+ action.setObjBos(bosPath);
|
|
|
+ // action.setObjPath(path);
|
|
|
+ // action.setObjPath(height + "/" + DateUtils.createFilesByDate() + "/" + fileName);
|
|
|
+ action.setObjPath(height + "/" + fileDate + "/" + name);
|
|
|
+ // cnt = actionMapper.insert(action);
|
|
|
+ // todo 20210705 新增关键动作视频数据是否存在逻辑。
|
|
|
+ // log.info("before tmpspgl gjdzstatus:{}",tmpSpgl.getGjdzstatus());
|
|
|
+ // tmpSpgl.setGjdzstatus("1");
|
|
|
+ // log.info("after tmpspgl gjdzstatus:{}",tmpSpgl.getGjdzstatus());
|
|
|
+ // spglMapper.updateById(tmpSpgl);
|
|
|
+ return action;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人体重建数据处理。
|
|
|
+ * @param tmpSpgl
|
|
|
+ * @param i
|
|
|
+ * @param height
|
|
|
+ * @param fileName
|
|
|
+ * @param skeletons
|
|
|
+ * @param files
|
|
|
+ * @param offset
|
|
|
+ * @param vertex
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public Frame insertVideoFrameInfos(Spgl tmpSpgl,int i,String height,JSONObject jsonObj, String fileName, String skeletons, MultipartFile[] files,String offset,String vertex) throws IOException {
|
|
|
+ /*
|
|
|
+ skeletons = "{
|
|
|
+ "1":[x11, y11, z11, x12, y12, z12, ...],
|
|
|
+ "2":[x21, y21, z21, x22, y22, z22, ...],
|
|
|
+ ...
|
|
|
+ }"
|
|
|
+ */
|
|
|
+ // 解析72个float数据。
|
|
|
+ JSONObject jsonObjVerx = JSON.parseObject(vertex);
|
|
|
+
|
|
|
+ // 骨架信息处理。
|
|
|
+ int forNum = jsonObj.size();
|
|
|
+ // 偏移量处理
|
|
|
+ JSONObject jsonObjOffset = JSON.parseObject(offset);
|
|
|
+ Frame frame = new Frame();
|
|
|
+ String vertex3d = jsonObj.get(String.valueOf(i)).toString();
|
|
|
+ log.info("vertex3d:{}",vertex3d);
|
|
|
+
|
|
|
+ //自增id,设为0实现自增
|
|
|
+ frame.setId(0);
|
|
|
+ frame.setVideoId(tmpSpgl.getId());
|
|
|
+ frame.setVideoName(tmpSpgl.getVideo().substring(tmpSpgl.getVideo().lastIndexOf("/")+1));
|
|
|
+ frame.setHeight(Integer.parseInt(height));
|
|
|
+ frame.setFrameName(i);
|
|
|
+ frame.setVertex3d(vertex3d);
|
|
|
+ frame.setFrameNum(forNum);
|
|
|
+ frame.setCreateTime(DateUtils.getCurrentTime());
|
|
|
+ String tmpOffset = jsonObjOffset.get(String.valueOf(i)).toString();
|
|
|
+ frame.setOffset(tmpOffset);
|
|
|
+ // 骨架信息
|
|
|
+ String verTex2d = jsonObjVerx.get(String.valueOf(i)).toString();
|
|
|
+ frame.setVertex2d(verTex2d);
|
|
|
+
|
|
|
+ //todo 保存关键帧3D模型相关信息
|
|
|
+ // frame.setObjBos(bosPath);
|
|
|
+ // frame.setObjPath(path);
|
|
|
+
|
|
|
+ log.info("frame:{}",JSON.toJSONString(frame));
|
|
|
+ return frame;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化3D视频查询语句。
|
|
|
+ * @param filename
|
|
|
+ * @param sStart
|
|
|
+ * @param sEnd
|
|
|
+ * @param eStart
|
|
|
+ * @param eEnd
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String,Object> sel3DMap(String filename,int sStart,int sEnd,int eStart,int eEnd){
|
|
|
+ String starttime = StringUtils.substring(filename, sStart, sEnd).replace("_", " ");
|
|
|
+ String endtime = StringUtils.substring(filename, eStart, eEnd).replace("_", " ");
|
|
|
+ String type = StringUtils.substringAfterLast(filename, "-");
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("starttime",starttime);
|
|
|
+ map.put("endtime",endtime);
|
|
|
+ map.put("type",type);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化更新spgl。
|
|
|
+ * @param type
|
|
|
+ * @param localPath
|
|
|
+ * @param bosKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Spgl init3DSpgls(Spgl sp,String type,String localPath,String bosKey){
|
|
|
+ // 更新表数据
|
|
|
+ if ("3dlhpg.mp4".equals(type)) {
|
|
|
+ sp.setLhpgpath(localPath);
|
|
|
+ sp.setLhpgkey(bosKey);
|
|
|
+ }
|
|
|
+ if ("3dztgj.mp4".equals(type)) {
|
|
|
+ sp.setZtgjpath(localPath);
|
|
|
+ sp.setZtgjkey(bosKey);
|
|
|
+ }
|
|
|
+ if ("3drtcj.mp4".equals(type)) {
|
|
|
+ sp.setRtcjpath(localPath);
|
|
|
+ sp.setRtcjkey(bosKey);
|
|
|
+ }
|
|
|
+ return sp;
|
|
|
+ }
|
|
|
+
|
|
|
+ // public Map<String, Object> getVideo(MultipartFile file, MultipartFile photo, String cam, String getTime, String psbName, String psb,List<User> userOnes,List<User> userTwos) throws IOException {
|
|
|
+ // String height = "";
|
|
|
+ // if (Constants.CAM_0.equals(cam) || Constants.CAM_1.equals(cam) || Constants.CAM_2.equals(cam) || Constants.CAM_3.equals(cam)) {
|
|
|
+ // // 10米跳台: 100 101 入场;102 103 出场。
|
|
|
+ // height = Constants.HEIGHT_TEN;
|
|
|
+ // } else if (Constants.CAM_4.equals(cam) || Constants.CAM_5.equals(cam) || Constants.CAM_6.equals(cam) || Constants.CAM_7.equals(cam)) {
|
|
|
+ // // 3米跳台:104 105 入场;106 107出场。
|
|
|
+ // height = Constants.HEIGHT_THREE;
|
|
|
+ // }
|
|
|
+ // // todo 0508 单双视频区分,故逻辑调整: psbName 是否包含","。
|
|
|
+ // int saved = 0;
|
|
|
+ // if (psbName.contains(",")) {
|
|
|
+ // // 双人视频 todo source
|
|
|
+ // String beforePsbName = StringUtils.substringBefore(psbName, ",");
|
|
|
+ // String afterPsbName = StringUtils.substringAfter(psbName, ",");
|
|
|
+ // String userOneId = "";
|
|
|
+ // String userTwoId = "";
|
|
|
+ //
|
|
|
+ // // Map<String, Object> userOneMap = new HashMap<>();
|
|
|
+ // // userOneMap.put("user_name", beforePsbName);
|
|
|
+ // // List<User> userOnes = userMapper.selectByMap(userOneMap);
|
|
|
+ //
|
|
|
+ // // Map<String, Object> userTwoMap = new HashMap<>();
|
|
|
+ // // userTwoMap.put("user_name", afterPsbName);
|
|
|
+ // // List<User> userTwos = userMapper.selectByMap(userTwoMap);
|
|
|
+ //
|
|
|
+ // if (userOnes.size() > 0 && null != userOnes.get(0) && StringUtils.isNotEmpty(userOnes.get(0).getUser_id())) {
|
|
|
+ // userOneId = userOnes.get(0).getUser_id();
|
|
|
+ // } else {
|
|
|
+ // // 若未识别出运动员,则默认运动员姓名
|
|
|
+ // userOneId = psbName.contains(",") ? "Unknow" : psbName;
|
|
|
+ // }
|
|
|
+ // // saved = commonCollectVideo(file,photo,cam,getTime,psbName,userOneId,height,beforePsbName);
|
|
|
+ // if ((userTwos.size() > 0 && null != userTwos.get(0) && StringUtils.isNotEmpty(userTwos.get(0).getUser_id()))) {
|
|
|
+ // userTwoId = userTwos.get(0).getUser_id();
|
|
|
+ // } else {
|
|
|
+ // userTwoId = psbName.contains(",") ? "Unknow" : psbName;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // // 根据psbname、
|
|
|
+ // // saved = commonCollectVideo(file2,file3,cam,getTime,psbName,userTwoId,height,afterPsbName);
|
|
|
+ // saved = commonDoubleCollectVideos(file, photo, cam, getTime, psbName, userOneId, userTwoId, height, beforePsbName, afterPsbName);
|
|
|
+ // } else {
|
|
|
+ // // 单人视频
|
|
|
+ // // 根据psbName获取运动员id
|
|
|
+ // String userid = "";
|
|
|
+ // // todo source
|
|
|
+ // // Map<String, Object> userMap = new HashMap<>();
|
|
|
+ // // 20210419 弃用。
|
|
|
+ // // userMap.put("name", psbName);
|
|
|
+ // // userMap.put("user_name", psbName);
|
|
|
+ // // List<User> users = userMapper.selectByMap(userMap);
|
|
|
+ // if (userOnes.size() > 0 && userOnes.get(0) != null && StringUtils.isNotEmpty(userOnes.get(0).getUser_id())) {
|
|
|
+ // userid = userOnes.get(0).getUser_id();
|
|
|
+ // } else {
|
|
|
+ // // 若未识别出运动员,则默认运动员姓名
|
|
|
+ // userid = psbName;
|
|
|
+ // }
|
|
|
+ // saved = commonSingleCollectVideo(file, photo, cam, getTime, psbName, userid, height);
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // Map<String, Object> resMap = new HashMap<>();
|
|
|
+ // resMap.put("code", saved > 0 ? "1" : "0");
|
|
|
+ // resMap.put("mes", "SUCC");
|
|
|
+ // resMap.put("data", saved);
|
|
|
+ // return resMap;
|
|
|
+ // }
|
|
|
+
|
|
|
+}
|