|
@@ -3652,4 +3652,172 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
//sceneService.updateScreencapMusic(sceneNum, voiceSrc);
|
|
|
return ResultData.ok(voiceSrc);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData uploadROIVideo(String sceneNum, String fileName, MultipartFile file, String planId, String rect,
|
|
|
+ String videoDirMatrix, String dir, String hfov, String vfov) throws Exception {
|
|
|
+ if(StrUtil.isEmpty(sceneNum) || StrUtil.isEmpty(fileName) ||
|
|
|
+ StrUtil.isEmpty(planId) || StrUtil.isEmpty(rect)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
+ }
|
|
|
+
|
|
|
+ ScenePro sceneProEntity = this.findBySceneNum(sceneNum);
|
|
|
+ if(sceneProEntity == null){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuffer dataBuf = new StringBuffer()
|
|
|
+ .append("data").append(File.separator)
|
|
|
+ .append("data").append(sceneProEntity.getNum())
|
|
|
+ .append(File.separator);
|
|
|
+
|
|
|
+ StringBuffer dataBuffer = new StringBuffer(ConstantFilePath.SCENE_PATH).append(dataBuf.toString());
|
|
|
+
|
|
|
+
|
|
|
+ String path = sceneProEntity.getDataSource();
|
|
|
+
|
|
|
+ if(path != null && !"".equals(path) && path.startsWith("http")){
|
|
|
+ path = ConstantFilePath.BUILD_MODEL_PATH + File.separator + path.split("/")[path.split("/").length - 2];
|
|
|
+ }
|
|
|
+ String target = path + "_roi";
|
|
|
+
|
|
|
+ FileUtils.deleteDirectory(target);
|
|
|
+
|
|
|
+ //文件上传的位置可以自定义
|
|
|
+ String filePath = target + File.separator + "extras" + File.separator + fileName;
|
|
|
+ File targetFile = new File(filePath);
|
|
|
+ if(!targetFile.getParentFile().exists()){
|
|
|
+ targetFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(file == null){
|
|
|
+ FileUtils.copyFile(ConstantFilePath.SCENE_PATH + "video/video"+
|
|
|
+ sceneProEntity.getNum() + File.separator + fileName, filePath, true);
|
|
|
+ }else {
|
|
|
+ //上传文件
|
|
|
+ file.transferTo(targetFile);
|
|
|
+
|
|
|
+ FileUtils.copyFile(filePath, ConstantFilePath.SCENE_PATH + "video/video"+
|
|
|
+ sceneProEntity.getNum() + File.separator + fileName, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ String strsceneInfos = FileUtils.readFile(dataBuffer.toString() + "scene.json");
|
|
|
+ JSONObject scenejson = new JSONObject();
|
|
|
+ if(strsceneInfos!=null) {
|
|
|
+ scenejson = JSONObject.parseObject(strsceneInfos);
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject rectJson = JSON.parseObject(rect);
|
|
|
+
|
|
|
+ boolean noPanoId = true;
|
|
|
+ if(scenejson.containsKey("videosUser")){
|
|
|
+ jsonArray = scenejson.getJSONArray("videosUser");
|
|
|
+ for(int i = 0, len = jsonArray.size(); i < len; i++){
|
|
|
+ jsonObject = jsonArray.getJSONObject(i);
|
|
|
+ if(planId.equals(jsonObject.getString("panoId"))){
|
|
|
+ jsonObject.put("rect", rectJson);
|
|
|
+ jsonObject.put("name", fileName.substring(0, fileName.lastIndexOf(".")));
|
|
|
+// jsonObject.put("videoDirMatrix", JSON.parseArray(videoDirMatrix));
|
|
|
+ jsonObject.put("dir", JSON.parseObject(dir));
|
|
|
+ jsonObject.put("hfov", hfov);
|
|
|
+ jsonObject.put("vfov", vfov);
|
|
|
+ noPanoId = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(noPanoId){
|
|
|
+ jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("name", fileName.substring(0, fileName.lastIndexOf(".")));
|
|
|
+ jsonObject.put("panoId", planId);
|
|
|
+ jsonObject.put("rect", rectJson);
|
|
|
+// jsonObject.put("videoDirMatrix", JSON.parseArray(videoDirMatrix));
|
|
|
+ jsonObject.put("dir", JSON.parseObject(dir));
|
|
|
+ jsonObject.put("hfov", hfov);
|
|
|
+ jsonObject.put("vfov", vfov);
|
|
|
+ if(!jsonArray.contains(jsonObject)){
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //保存rect的json数据
|
|
|
+ FileUtils.writeFile(target + File.separator + "extras" + File.separator + "video-ROI.json", jsonObject.toJSONString());
|
|
|
+ //复制原始图片
|
|
|
+ FileUtils.copyFile(path + "/caches/images/" + planId + ".jpg",
|
|
|
+ target + File.separator + "extras" + File.separator + planId + ".jpg", true);
|
|
|
+
|
|
|
+ FileUtils.copyFile(path + File.separator + "data.json", target + File.separator+"data.json", true);
|
|
|
+ FileUtils.copyFile(path + File.separator + "project.json", target + File.separator+"project.json", true);
|
|
|
+
|
|
|
+ //data.json增加extras为执行重建算法
|
|
|
+ String project = FileUtils.readFile(target + File.separator+"project.json");
|
|
|
+ if(project != null){
|
|
|
+ JSONObject projectJson = JSONObject.parseObject(project);
|
|
|
+ projectJson.put("parent", projectJson.get("uuid"));
|
|
|
+ projectJson.put("uuid", UUID.randomUUID().toString());
|
|
|
+ projectJson.put("time", System.currentTimeMillis());
|
|
|
+ FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ String data = FileUtils.readFile(target + File.separator+"data.json");
|
|
|
+ if(data != null){
|
|
|
+ JSONObject dataJson = JSONObject.parseObject(data);
|
|
|
+ //V5表示不需要生成high,low文件
|
|
|
+ dataJson.put("skybox_type", "SKYBOX_V5");
|
|
|
+ dataJson.put("split_type", "SPLIT_V11");
|
|
|
+ FileUtils.writeFile(target + File.separator+"data.json", new String(dataJson.toString().getBytes(), "UTF-8"));
|
|
|
+ }
|
|
|
+
|
|
|
+ //进行计算
|
|
|
+ log.info("绿幕抠图视频:开始建模——" + sceneProEntity.getNum());
|
|
|
+ CreateObjUtil.build3dModel2(target , "1");
|
|
|
+
|
|
|
+ //读取upload文件,检验需要上传的文件是否存在
|
|
|
+ String uploadData = FileUtils.readFile(target + File.separator + "results" +File.separator+"upload.json");
|
|
|
+ JSONObject uploadJson = null;
|
|
|
+ JSONArray array = null;
|
|
|
+ if(uploadData!=null) {
|
|
|
+ uploadJson = JSONObject.parseObject(uploadData);
|
|
|
+ array = uploadJson.getJSONArray("upload");
|
|
|
+ }
|
|
|
+ if(array == null){
|
|
|
+ throw new Exception("upload.json数据出错");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ JSONObject fileJson = null;
|
|
|
+ for(int i = 0, len = array.size(); i < len; i++){
|
|
|
+ fileJson = array.getJSONObject(i);
|
|
|
+ fileName = fileJson.getString("file");
|
|
|
+ //文件不存在抛出异常
|
|
|
+ if(!new File(target + File.separator + "results" +File.separator + fileName).exists()){
|
|
|
+ throw new Exception(target + File.separator + "results" +File.separator + fileName+"文件不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(fileJson.getIntValue("clazz") == 19 ){
|
|
|
+ map.put(target + File.separator + "results" + File.separator+ fileName,"video/video"+
|
|
|
+ sceneProEntity.getNum() + File.separator + fileName.replace("videos/", ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ fYunFileService.uploadMulFiles(map);
|
|
|
+
|
|
|
+ scenejson.put("videosUser", jsonArray.toJSONString());
|
|
|
+ scenejson.put("imagesVersion", scenejson.getIntValue("imagesVersion") + 1);
|
|
|
+
|
|
|
+ FileUtils.writeFile(dataBuffer.toString() + "scene.json", scenejson.toString());
|
|
|
+
|
|
|
+ SceneProEdit sceneProEditEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
|
|
|
+ if(sceneProEditEntity != null){
|
|
|
+ sceneProEditEntity.setVideosUser(jsonArray.toJSONString());
|
|
|
+ sceneProEditEntity.setImagesVersion(sceneProEditEntity.getImagesVersion() + 1);
|
|
|
+ sceneProEditService.updateById(sceneProEditEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
}
|