Qt上实时点云可视化

在qt上模拟ros去接收点云,并将点云数据3d可视化。不过本人并没有实现使用ros+qt的方法去订阅话题来获得点云,如有大佬实现可以留下链接。可以采用boost::asio去实现,这里采用简单易懂的tcp去接收点云。

服务端

服务器端是随机生成5000-10000个点云,并通过tcp发送给服务器。

tcp.cpp 

#include <QCoreApplication>
#include <QTcpServer>
#include <QTcpSocket>
#include <QThread>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/compression/octree_pointcloud_compression.h>
#include <pcl/io/io.h>

using PointCloud = pcl::PointCloud<pcl::PointXYZ>;

class Server : public QTcpServer {
    Q_OBJECT

public:
    Server(QObject *parent = nullptr) : QTcpServer(parent) {
        if (!this->listen(QHostAddress::Any, 1234)) {
            qCritical() << "Unable to start the server: " << this->errorString();
        } else {
            qDebug() << "Server started...";
        }
    }

protected:
    void incomingConnection(qintptr socketDescriptor) override {
        QTcpSocket *socket = new QTcpSocket(this);
        socket->setSocketDescriptor(socketDescriptor);
        connect(socket, &QTcpSocket::disconnected, socket, &QTcpSocket::deleteLater);
        sendPointCloud(socket);
    }

private slots:
    void sendPointCloud(QTcpSocket *socket) {
        while (socket->state() == QAbstractSocket::ConnectedState) {
            PointCloud::Ptr cloud(new PointCloud);
            generateRandomPointCloud(cloud, 5000 + qrand() % 5001);  // 生成5000到10000个点
            //压缩点云数据
            std::stringstream compressedData;
            pcl::io::OctreePointCloudCompression<pcl::PointXYZ>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北海__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值