Qt PCL学习(二):点云读取与保存

注意事项

  • 版本一览:Qt 5.15.2 + PCL 1.12.1 + VTK 9.1.0
  • 前置内容:Qt PCL学习(一):环境搭建

0. 效果演示

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

1. pcl_open_save.pro

QT       += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets// 添加下行代码(根据自己安装目录进行修改)
include(D:/PCL1.12.1/pcl1.12.1.pri)

2. mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QDebug>
#include <QColorDialog>
#include <QMessageBox>
#include <QFileDialog>
#include <QTime>
#include <QDir>
#include <QFile>
#include <QtMath>
#include <QWindow>
#include <QAction>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QIcon>
#include <QMenuBar>
#include <QMenu>
#include <QToolBar>
#include <QStatusBar>
#include <QFont>
#include <QString>
#include <QTextBrowser>#include <QVTKOpenGLNativeWidget.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkRenderWindow.h>
#include <vtkAutoInit.h>#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/visualization/pcl_visualizer.h>typedef pcl::PointXYZ PointT;
typedef pcl::PointCloud<PointT> PointCloudT;
typedef pcl::visualization::PCLVisualizer PCLViewer;
typedef std::shared_ptr<PointCloudT> PointCloudPtr;VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow {Q_OBJECTpublic:MainWindow(QWidget *parent = nullptr);~MainWindow();private slots:void open_clicked();void save_clicked();private:Ui::MainWindow *ui;PointCloudPtr cloudptr;PCLViewer::Ptr cloud_viewer;
};
#endif // MAINWINDOW_H

3. mainwindow.cpp

#pragma execution_character_set("utf-8")#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {ui->setupUi(this);// 设置窗口标题和 logothis->setWindowTitle("CloudOne");this->setWindowIcon(QIcon(":/resourse/icon.ico"));// 初始化点云数据 cloudptrcloudptr.reset(new PointCloudT);// 创建菜单栏QMenuBar *menu_bar = new QMenuBar(this);this->setMenuBar(menu_bar);menu_bar->setStyleSheet("font-size : 16px");// 1、File 下拉列表QMenu *file_menu = new QMenu("File", menu_bar);QAction *open_action = new QAction("Open File");QAction *save_action = new QAction("Save File");QAction *exit_action = new QAction("Exit");// 添加动作到文件菜单file_menu->addAction(open_action);file_menu->addAction(save_action);file_menu->addSeparator();  // 添加菜单分隔符将 exit 单独隔离开file_menu->addAction(exit_action);// 把 File 添加到菜单栏menu_bar->addMenu(file_menu);// 信号与槽函数链接connect(open_action, SIGNAL(triggered()), this, SLOT(open_clicked()));  // 打开文件connect(save_action, SIGNAL(triggered()), this, SLOT(save_clicked()));  // 保存文件connect(exit_action, SIGNAL(triggered()), this, SLOT(close()));         // 退出
}MainWindow::~MainWindow() {delete ui;
}void MainWindow::open_clicked() {// this:代表当前对话框的父对象;tr("open file"):作为对话框的标题显示在标题栏中,使用 tr 函数表示这是一个需要翻译的文本// "":代表对话框的初始目录,这里为空表示没有指定初始目录// tr("pcb files(*.pcd *.ply *.txt) ;;All files (*.*)"):过滤器,决定在对话框中只能选择指定类型的文件QString fileName = QFileDialog::getOpenFileName(this, tr("open  file"), "", tr("point cloud files(*.pcd *.ply) ;; All files (*.*)"));if (fileName.isEmpty()) {return;}if (fileName.endsWith("ply")) {qDebug() << fileName;if (pcl::io::loadPLYFile(fileName.toStdString(), *cloudptr) == -1) {qDebug() << "Couldn't read .ply file \n";return ;}} else if (fileName.endsWith("pcd")) {qDebug() << fileName;if (pcl::io::loadPCDFile(fileName.toStdString(), *cloudptr) == -1) {qDebug() << "Couldn't read .pcd file \n";return;}} else {QMessageBox::warning(this, "Warning", "Wrong format!");}// 创建 PCLViewer 对象并设置窗口标题cloud_viewer.reset(new PCLViewer("Viewer"));cloud_viewer->setShowFPS(true);// 将 cloud_viewer 的渲染窗口嵌入到 QWidget 中auto viewerWinId = QWindow::fromWinId((WId)cloud_viewer->getRenderWindow()->GetGenericWindowId());QWidget *widget = QWidget::createWindowContainer(viewerWinId, nullptr);// 创建 QVBoxLayout 对象并将 QWidget 添加到其中QVBoxLayout *mainLayout = new QVBoxLayout;mainLayout->addWidget(widget);centralWidget()->setLayout(mainLayout);// 设置颜色处理器,将点云数据添加到 cloud_viewer 中const std::string axis = "z";pcl::visualization::PointCloudColorHandlerGenericField<PointT> color_handler(cloudptr, axis);cloud_viewer->addPointCloud(cloudptr, color_handler, "cloud");cloud_viewer->addPointCloud(cloudptr, "cloud");
}void MainWindow::save_clicked() {int return_status;QString filename = QFileDialog::getSaveFileName(this, tr("Open point cloud"), "", tr("Point cloud data (*.pcd *.ply)"));if (cloudptr->empty()) {return;} else {if (filename.isEmpty()) {return;}if (filename.endsWith(".pcd", Qt::CaseInsensitive)) {return_status = pcl::io::savePCDFileBinary(filename.toStdString(), *cloudptr);} else if (filename.endsWith(".ply", Qt::CaseInsensitive)) {return_status = pcl::io::savePLYFileBinary(filename.toStdString(), *cloudptr);} else {filename.append(".ply");return_status = pcl::io::savePLYFileBinary(filename.toStdString(), *cloudptr);}if (return_status != 0) {PCL_ERROR("Error writing point cloud %s\n", filename.toStdString().c_str());return;}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2775899.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

[word] word2019段落中创建纵横混排的方法图解教程 #知识分享#其他#职场发展

word2019段落中创建纵横混排的方法图解教程 有时候在word文档中需要让文字纵横混排&#xff0c;word2019正好为我们带来了纵横混排的功能了&#xff0c;今天我们就来给大家介绍一下word2019段落中创建纵横混排的方法。 步骤1&#xff1a;打开Word文档&#xff0c;选中需要纵向…

MT4和MT5中如何创建挂单,很简单,fpmarkets1秒教会

其实在MT4和MT5中创建挂单是非常容易的&#xff0c;今天fpmarkets1秒教会&#xff0c;接下来一步一步的演示&#xff1a; 首先单击新订单&#xff0c;将出现设置窗口。在“类型”选项卡中选择“按待定顺序”。 接着选择挂单的类型。选择买入止损单&#xff0c;并指定订单执行的…

【Leetcode】236. 二叉树的最近公共祖先

文章目录 题目思路代码结果 题目 题目链接 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为&#xff1a;“对于有根树 T 的两个节点 p、q&#xff0c;最近公共祖先表示为一个节点 x&#xff0c;满足 x 是 p、q 的祖先且 x 的深度尽可…

Python爬虫http基本原理#2

Python爬虫逆向系列&#xff08;更新中&#xff09;&#xff1a;http://t.csdnimg.cn/5gvI3 HTTP 基本原理 在本节中&#xff0c;我们会详细了解 HTTP 的基本原理&#xff0c;了解在浏览器中敲入 URL 到获取网页内容之间发生了什么。了解了这些内容&#xff0c;有助于我们进一…

攻防世界 CTF Web方向 引导模式-难度1 —— 1-10题 wp精讲

目录 view_source robots backup cookie disabled_button get_post weak_auth simple_php Training-WWW-Robots view_source 题目描述: X老师让小宁同学查看一个网页的源代码&#xff0c;但小宁同学发现鼠标右键好像不管用了。 不能按右键&#xff0c;按F12 robots …

备战蓝桥杯---搜索(完结篇)

再看一道不完全是搜索的题&#xff1a; 解法1&#xff1a;贪心并查集&#xff1a; 把冲突事件从大到小排&#xff0c;判断是否两个在同一集合&#xff0c;在的话就返回&#xff0c;不在的话就合并。 下面是AC代码&#xff1a; #include<bits/stdc.h> using namespace …

CTF--Web安全--SQL注入之‘绕过方法’

一、什么是绕过注入 众所周知&#xff0c;SQL注入是利用源码中的漏洞进行注入的&#xff0c;但是有攻击手段&#xff0c;就会有防御手段。很多题目和网站会在源码中设置反SQL注入的机制。SQL注入中常用的命令&#xff0c;符号&#xff0c;甚至空格&#xff0c;会在反SQL机制中…

从github上拉取项目到pycharm中

有两种方法&#xff0c;方法一较为简单&#xff0c;方法二用到了git bash&#xff0c;推荐方法一 目录 有两种方法&#xff0c;方法一较为简单&#xff0c;方法二用到了git bash&#xff0c;推荐方法一方法一&#xff1a;方法二&#xff1a; 方法一&#xff1a; 在github上复制…

【开源】JAVA+Vue.js实现高校实验室管理系统

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、研究内容2.1 实验室类型模块2.2 实验室模块2.3 实验管理模块2.4 实验设备模块2.5 实验订单模块 三、系统设计3.1 用例设计3.2 数据库设计 四、系统展示五、样例代码5.1 查询实验室设备5.2 实验放号5.3 实验预定 六、免责说明 一、摘…

基于鲲鹏服务器的LNMP配置

基于鲲鹏服务器的LNMP配置 系统 Centos8 # cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core) 卸载已经存在的旧版本的安装包 # rpm -qa | grep php #查看已经安装的PHP旧版本# rpm -qa | grep php | xargs rpm -e #卸载已经安装的旧版&#xff0c;如果提示有…

介绍页引导页业务网搭建HTML网站源码

介绍页引导页业务网搭建HTML网站源码 介绍页引导页业务网搭建网站源码&#xff0c;HTMLJSCSS,卡片式风格业务介绍&#xff0c;简单大气,喜欢的朋友拿去吧&#xff0c;源码免积分下载 https://download.csdn.net/download/huayula/88821635 蓝奏云&#xff1a;https://wfr.lan…

Django(十)

1. Ajax请求 浏览器向网站发送请求时&#xff1a;URL 和 表单的形式提交。 GETPOST 特点&#xff1a;页面刷新。 除此之外&#xff0c;也可以基于Ajax向后台发送请求&#xff08;偷偷的发送请求&#xff09;。 依赖jQuery编写ajax代码 $.ajax({url:"发送的地址"…

Go 语言 for 的用法

For statements 本文简单翻译了 Go 语言中 for 的三种用法&#xff0c;可快速学习 Go 语言 for 的使用方法&#xff0c;希望本文能为你解开一些关于 for 的疑惑。详细内容可见文档 For statements。 For statements with single condition 在最简单的形式中&#xff0c;只要…

notepad++成功安装后默认显示英文怎么设置中文界面?

前几天使用电脑华为管家清理电脑后&#xff0c;发现一直使用的notepad软件变回了英文界面&#xff0c;跟刚成功安装的时候一样&#xff0c;那么应该怎么设置为中文界面呢&#xff1f;具体操作如下&#xff1a; 1、打开notepad软件&#xff0c;点击菜单栏“Settings – Prefere…

video / image上传操作-校验、截取首帧和正方形预览图等

常见video / image上传操作-校验、截取首帧和正方形预览图等。 上回搞了一个视频和图片上传和校验的需求&#xff0c;感觉学到很多&#xff0c;一些常见的函数记录如下&#xff1a; 1. 图片校验尺寸 const { maxCount 30, maxWidth, maxHeight, minHeight 200, minWidth …

Linux笔记之expect和bash脚本监听输出并在匹配到指定字符串时发送中断信号

Linux笔记之expect和bash脚本监听输出并在匹配到指定字符串时发送中断信号 code review! 文章目录 Linux笔记之expect和bash脚本监听输出并在匹配到指定字符串时发送中断信号1.expect2.bash 1.expect 在Expect脚本中&#xff0c;你可以使用expect来监听程序输出&#xff0c;…

一周学会Django5 Python Web开发-Django5创建项目(用命令方式)

锋哥原创的Python Web开发 Django5视频教程&#xff1a; 2024版 Django5 Python web开发 视频教程(无废话版) 玩命更新中~_哔哩哔哩_bilibili2024版 Django5 Python web开发 视频教程(无废话版) 玩命更新中~共计11条视频&#xff0c;包括&#xff1a;2024版 Django5 Python we…

C#,雷卡曼数(Recamán Number)的算法与源代码

1 雷卡曼数&#xff08;Recamn Number&#xff09; 雷卡曼数&#xff08;Recamn Number&#xff09;&#xff0c;即Recaman序列被定义如下&#xff1a; (1) a[0]0; (2) 如果a[m-1]-m>0并且这个值在序列中不存在&#xff0c;则a[m]a[m-1]-m; (3) 否则a[m]a[m-1]m; 雷卡曼序…

STM32之USART

概述 串口通信&#xff0c;通用异步收发传输器&#xff08;Universal Asynchronous Receiver/Transmitter &#xff09;&#xff0c;简称UART&#xff1b;而USART&#xff08;Universal Synchronous/Asynchronous Receiver/Transmitter&#xff09;通用同步收发传输器。 USAR…

【每日一题】LeetCode——反转链表

&#x1f4da;博客主页&#xff1a;爱敲代码的小杨. ✨专栏&#xff1a;《Java SE语法》 | 《数据结构与算法》 | 《C生万物》 ❤️感谢大家点赞&#x1f44d;&#x1f3fb;收藏⭐评论✍&#x1f3fb;&#xff0c;您的三连就是我持续更新的动力❤️ &#x1f64f;小杨水平有…