当前位置:网站首页>tkinter窗口选择pcd文件并显示点云(open3d)

tkinter窗口选择pcd文件并显示点云(open3d)

2022-07-07 01:36:00 程序员进化不脱发!

测试用兔子
在这里插入图片描述


# !/user/bin/env Python3
# -*- coding:utf-8 -*-
import open3d as o3d
import numpy as np
import os
import tkinter as tk
from tkinter import filedialog, dialog
import open3d as o3d
import numpy as np

file_path = ''
file_text = ''
vis = None

def init_window():
    # ------------------------初始化显示窗口-------------------------
    vis = o3d.visualization.Visualizer()
    vis.create_window(window_name='pcd', width=800, height=600)
    # ------------------------可视化参数设置-------------------------
    opt = vis.get_render_option()
    opt.background_color = np.asarray([0, 0, 0])  # 设置背景色
    opt.point_size = 2  # 设置点云大小
    opt.show_coordinate_frame = True  # 设置是否显示坐标系


def updata_pcd(vis):
    pcd = o3d.io.read_point_cloud(pcd_path)
    vis.update_geometry(pcd)  # 更新窗口中显示的内容
    vis.add_geometry(pcd)  # 添加点云到可视化窗口
    vis.poll_events()
    vis.update_renderer()  # 更新显示窗口
    vis.clear_geometries()  # 清空显示内容

def choose_pcd():
    ''' 打开文件 :return:local_ '''
    global file_path
    global file_text
    file_path = filedialog.askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('H:/')))
    print('打开文件:', file_path)
    if file_path is not None:

        file_text = file_path
        text1.insert('insert', file_text)

def open_point():
    global file_text
    print("加载pcd文件路径:" + file_text)
    pcd = o3d.io.read_point_cloud(file_text)
    print(pcd)  # 输出点云点的个数
    print(np.asarray(pcd.points))  # 输出点的三维坐标
    print('给所有的点上一个统一的颜色,颜色是在RGB空间得[0,1]范围内得值')
    pcd.paint_uniform_color([0, 1, 0])
    o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)
    o3d.visualization.draw_geometries([pcd])



if __name__ == '__main__':
    window = tk.Tk()
    window.title('窗口标题')  # 标题
    window.geometry('500x300')  # 窗口尺寸
    text1 = tk.Text(window, width=50, height=10, bg='orange', font=('Arial', 12))
    text1.pack()

    vis1 = init_window()
    bt1 = tk.Button(window, text='选择pcd文件', width=15, height=2, command=choose_pcd)
    bt1.pack()

    bt2 = tk.Button(window, text='打开点云', width=15, height=2, command=open_point)
    bt2.pack()

    window.mainloop()  # 显示




原网站

版权声明
本文为[程序员进化不脱发!]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43134049/article/details/125598438