windows下基于krpano的全自动化处理平台

简介: 本文介绍了一种基于krpano的全自动处理平台,可以自动发布全景实战案例。该平台完整构建了完整的生命周期,从图片上传,到后台图片切片等,基本具备服务能力。

     五一劳动节,首先祝所有的劳动者节日快乐,向奋战在劳动的抗疫战士致敬。本想出去走一走,无奈人太多,就不给景区增加负担。

     之前有一些文章陆续进行了全景照片的处理说明。之前的文章链接,1、实战!使用pano2vr生成html5全景页面 2、基于Three.js的全景展示框架-TPano 3、全景自动切片技术-krpano初识。本次分享一个比较真实的全景处理案例,可以自动完成全景照片的切片及展示场景需求。

     环境说明:

1、JDK8、MySQL5.7、SpringBoot、Hibernate、krpano-1.19-pr13、Thymeleaf、JQuery3.4.1、Bootstrap3.3.7

下面正式进入正题。

第一步、项目Pom.xml定义

如下代码所示:

<?xmlversion="1.0" encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.0.RELEASE</version><relativePath/><!-- lookup parent from repository --></parent><groupId>cn.com.scitc</groupId><artifactId>pano</artifactId><version>1</version><packaging>war</packaging><name>pano</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-test</artifactId><scope>test</scope></dependency></dependencies></project>

第二步、安装krpano

具体步骤可参见krpano的官网或者网络教程。这里不进行赘述。在服务器上执行脚本命令行完成切片的功能。核心代码结构截图如下:

image.png

在controller中定义了所有的页面交互控制类。每个控制类根据命令已经大致可以猜到具体的用途。文中核心的转换逻辑写在PageController中,核心代码如下:

// 执行上传@RequestMapping("/upload")
publicStringupload(@RequestParam("file") MultipartFilefile, Modelmodel) throwsIOException {
//获取用户名UserDetailsuserDetails= (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Stringname=userDetails.getUsername();
// 获取上传文件名Stringfilename=file.getOriginalFilename();
StringfileName=filename.substring(0,filename.length() -5);
// 定义上传文件保存路径Stringpath=filePath+"rotPhoto/"+name;
// 新建文件Filefilepath=newFile(path, filename);
// 判断路径是否存在,如果不存在就创建一个if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
        }
try {
// 写入文件file.transferTo(newFile(path+File.separator+filename));
        } catch (IOExceptione) {
e.printStackTrace();
        }
// 将src路径发送至html页面model.addAttribute("filename", "/images/rotPhoto/"+name+"\\"+filename);
Stringcmd;
Stringappction="E:/krpano/krpano-1.19-pr13/krpanotools64.exe makepano -config=templates/vtour-normal.config D:/code/pano/src/main/resources/static/images/rotPhoto/";
cmd=appction+name+"/"+filename;
try {
Processprocess=Runtime.getRuntime().exec(cmd);
InputStreamis=process.getInputStream();
InputStreamReaderisr=newInputStreamReader(is);
BufferedReaderbr=newBufferedReader(isr);
Stringcontent=br.readLine();
while (content!=null) {
System.out.println(content);
content=br.readLine();
                }
            } catch (IOExceptione) {
e.printStackTrace();
            }
String[] wenname=newString[4];
Stringpathfile="D:/code/pano/src/main/resources/static/images/rotPhoto/";
wenname[0] =pathfile+name+"/vtour/usergoods.html";
wenname[1] =pathfile+name+"/vtour/tour.swf";
wenname[2] =pathfile+name+"/vtour/tour_testingserver.exe";
wenname[3] =pathfile+name+"/vtour/tour_testingserver_macos";
for (inti=0; i<wenname.length; i++){
Filefilethree=newFile(wenname[i]);
filethree.delete();
            }
//            删除生成的重复的文件包String[] wennametwo=newString[2];
wennametwo[0] =pathfile+name+"/vtour/plugins";
wennametwo[1] =pathfile+name+"/vtour/skin";
for (inti=0; i<wennametwo.length; i++){
Filefilefour=newFile(wennametwo[i]);
DeleteFiledeleteFile=newDeleteFile();
deleteFile.deleteFile(filefour);
        }
try {
Patternpattern=Pattern.compile("<include url=\"skin/vtourskin.xml\" />", Pattern.CASE_INSENSITIVE); // 要匹配的字段内容,正则表达式Matchermatcher=pattern.matcher("");
List<String>lines=Files.readAllLines(Paths.get(pathfile+name+"/vtour/tour.xml")); // 读取文本文件for (inti=0; i<lines.size(); i++) {
matcher.reset(lines.get(i));
if (matcher.find()) { // 匹配正则表达式lines.remove(i);
lines.add(i, "<include url=\"../../../../skin/vtourskin.xml\" />");
                }
            }
Files.write(Paths.get(pathfile+name+"/vtour/tour.xml"), lines);
        } catch (IOExceptione) {
e.printStackTrace();
        }
FileoldFile=newFile("D:/code/pano/src/main/resources/static/images/rotPhoto/"+name+"/vtour");
if(!oldFile.exists()){
oldFile.createNewFile();
        }
StringrootPath=oldFile.getParent();
FilenewFile=newFile(rootPath+File.separator+fileName);
if (oldFile.renameTo(newFile)){
log.info("修改成功!");
        }else{
log.info("修改失败");
        }
return"upload";
    }

后台接收前台上传的文件后,即开始进行全景切图。

第三步、全景图片展示核心代码如下:

@Controller@RequestMapping("/")
publicclassHomeController {
privateLoglog=LogFactory.getLog(getClass());
@GetMapping("/include/navstyle")
publicStringnavstyle(){
return"/include/navstyle";
    }
@RequestMapping("/select")
privateStringselect(Modelmodel) {
UserDetailsuserDetails= (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Stringname=userDetails.getUsername();
Filefile=newFile("D:/code/pano/src/main/resources/static/images/rotPhoto/"+name);
if (!file.exists()){
model.addAttribute("goods","/prompt");
        }else {
model.addAttribute("goods","/goods");
        }
if (!file.exists()){
model.addAttribute("works","/prompt");
        }else {
model.addAttribute("works","/userwork");
        }
return"select";
    }
@RequestMapping("/include/nav")
privateStringnav() {
return"/include/nav";
    }
@RequestMapping("/include/footer")
privateStringfooter() {
return"/include/footer";
    }
@RequestMapping("/prompt")
privateStringprompt() {
return"/prompt";
    }
}

最后我们来看下展示的效果。

image.png

首页展示

image.png

万里长城展示

image.png

全景处理

image.png

全景处理

     总结:本文介绍了一种基于krpano的全自动处理平台,可以自动发布全景实战案例。完整构建了完整的生命周期,从图片上传,到后台图片切片等,基本具备服务能力。但是本平台也存在一定的缺点,比如:页面UI不够美观、不兼容Linux平台、没有采用文件存储模式、图片处理没有异步化,系统容错性不好、krpano的工作路径是固定的,没有设置成动态路径,于此同时,还有一些bug需要调整。

     不过总体来说,是一个很好的全景处理程序,提供了比较详细的处理逻辑。有兴趣的朋友可以在此基础之上进行二次开发和扩展,比如去弥补上述的一些缺陷也是未尝不可以的。最后分享开源地址:https://gitee.com/hszzz/pano.git,有需要的小伙伴可以自行下载。

目录
相关文章
|
2月前
|
资源调度 测试技术 Linux
一款接口自动化神器—开源接口测试平台Lim(Less is More)
一款接口自动化神器—开源接口测试平台Lim(Less is More)
225 2
|
2月前
|
BI Windows Python
python报表自动化系列 - 在Windows中打开指定目录
python报表自动化系列 - 在Windows中打开指定目录
40 1
|
2月前
|
Go 数据处理 Docker
elk stack部署自动化日志收集分析平台
elk stack部署自动化日志收集分析平台
109 0
EMQ
|
3天前
|
物联网 Linux C语言
在 Windows 平台搭建 MQTT 服务
NanoMQ 有着强大的跨平台和可兼容能力,不仅可以用于以 Linux 为基础的各类平台,也为 Windows 平台提供了 MQTT 服务的新选择。
EMQ
11 1
在 Windows 平台搭建 MQTT 服务
|
26天前
|
Python Windows
在 Windows 平台下打包 Python 多进程代码为 exe 文件的问题及解决方案
在使用 Python 进行多进程编程时,在 Windows 平台下可能会出现将代码打包为 exe 文件后无法正常运行的问题。这个问题主要是由于在 Windows 下创建新的进程需要复制父进程的内存空间,而 Python 多进程机制需要先完成父进程的初始化阶段后才能启动子进程,所以在这个过程中可能会出现错误。此外,由于没有显式导入 Python 解释器,也会导致 Python 解释器无法正常工作。为了解决这个问题,我们可以使用函数。
26 5
|
1月前
|
消息中间件 Kubernetes Kafka
AutoMQ 自动化持续测试平台技术内幕
Marathon 是一个针对流系统 AutoMQ 的自动化持续测试平台,旨在在模拟生产环境和各种故障场景中验证 SLA 的可靠性。设计原则包括易拓展、可观测和低成本。平台采用分布式架构,Controller 负责资源管理和任务编排,动态调整 Worker 数量和配置,而 Worker 是无状态的,用于生成负载和上报数据。系统基于 K8S,利用服务发现、事件总线和 Spot 实例降低成本并提高弹性。测试场景以代码形式描述,支持不同流量模型和断言,提供丰富的可观测性和告警功能。未来,Marathon 有望泛化为适用于各种分布式系统的测试平台。
31 0
AutoMQ 自动化持续测试平台技术内幕
|
2月前
|
弹性计算 运维 监控
【阿里云云原生专栏】自动化运维的艺术:阿里云云原生平台的自动化运维工具集
【5月更文挑战第28天】阿里云云原生平台提供全面的自动化运维工具,涵盖监控告警、资源管理、部署更新、故障自愈、安全管理和数据备份等方面,简化运维工作,增强系统稳定性。通过智能工具集,运维人员能专注于业务优化,实现高效运维,为企业数字化转型提供有力支持。
205 3
|
2月前
|
数据库 Windows
第五十章 使用 ^SystemPerformance 监视性能 - Microsoft Windows 平台的 InterSystems IRIS 性能数据报告
第五十章 使用 ^SystemPerformance 监视性能 - Microsoft Windows 平台的 InterSystems IRIS 性能数据报告
30 0
|
2月前
|
Windows
LabVIEW在Windows平台上的图形导入
LabVIEW在Windows平台上的图形导入
32 0
|
2月前
|
机器学习/深度学习 人工智能 自然语言处理