Open3D实时点云显示

文章目录


前言

一般情况我们通过open3d中的draw_geometries()进行点云可视化,但这个函数会锁定一个进程直到可视化的窗口被关闭,才会继续渲染下一帧点云图像,无法做到点云持续的动态显示。本文介绍了一个自定义渲染循环的教程。


下面先展示下效果:
在这里插入图片描述


代码

# -*- coding: utf-8 -*-
# @Time : 2022/10/25 16:22
# @Author : JulyLi
# @File : inno_sdk.py

import open3d as o3d
import numpy as np
import queue
import threading
from os import path


def visualize_pointscloud(show_q):
    vis = o3d.visualization.Visualizer()
    vis.create_window(width=800, height=600)
    pointcloud = o3d.geometry.PointCloud()
    to_reset = True
    vis.add_geometry(pointcloud)

    while True:
        try:
            pcd = show_q.get()

            pcd = np.asarray(pcd.points).reshape((-1, 3))
            pointcloud.points = o3d.utility.Vector3dVector(pcd)
            # vis.update_geometry()
            # 注意,如果使用的是open3d 0.8.0以后的版本,这句话应该改为下面格式
            vis.update_geometry(pointcloud)
            if to_reset:
                vis.reset_view_point(True)
                to_reset = False
            vis.poll_events()
            vis.update_renderer()
        except:
            continue


if __name__ == '__main__':

    show_q = queue.Queue(1)
    visual = threading.Thread(target=visualize_pointscloud, args=(show_q,))
    visual.start()

    input_dir = r"D:\Bvision\PCL\9818"
    frame = 0
    while True:
        input_name = path.join(input_dir, str(frame)+".pcd")
        print(input_name)
        # 获取雷达数据
        pcd = o3d.io.read_point_cloud(input_name)

        if show_q.full():
            show_q.get()
        show_q.put(pcd)
        frame += 1  # 迭代读取下一张图片
        frame %= 98  # 由于文件夹中最多只有98图片,超出了,又会回到0,循环

总结

这里整体思想是按名称读取文件然后送入队列中,使用多线程进行点云显示,当文件读完之后,重新开始读取。
读者可以根据自己的数据情况修改,已完成实时点云显示。

参考文档:
https://blog.csdn.net/weixin_43419116/article/details/110987436
https://blog.csdn.net/suyunzzz/article/details/105183824
如果阅读本文对你有用,欢迎一键三连呀!!!
2022年11月18日15:38:30
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/JulyLi2019/article/details/127774752