当前位置:网站首页>Tkinter window selects PCD file and displays point cloud (open3d)

Tkinter window selects PCD file and displays point cloud (open3d)

2022-07-07 06:26:00 Programmers evolve without losing their hair!

Test rabbit
 Insert picture description here


# !/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():
    # ------------------------ Initialize the display window -------------------------
    vis = o3d.visualization.Visualizer()
    vis.create_window(window_name='pcd', width=800, height=600)
    # ------------------------ Visual parameter setting -------------------------
    opt = vis.get_render_option()
    opt.background_color = np.asarray([0, 0, 0])  #  Set background color 
    opt.point_size = 2  #  Set the point cloud size 
    opt.show_coordinate_frame = True  #  Set whether to display coordinate system 


def updata_pcd(vis):
    pcd = o3d.io.read_point_cloud(pcd_path)
    vis.update_geometry(pcd)  #  Update the contents displayed in the window 
    vis.add_geometry(pcd)  #  Add a point cloud to the visualization window 
    vis.poll_events()
    vis.update_renderer()  #  Update the display window 
    vis.clear_geometries()  #  Clear the display 

def choose_pcd():
    '''  Open file  :return:local_ '''
    global file_path
    global file_text
    file_path = filedialog.askopenfilename(title=u' Select File ', initialdir=(os.path.expanduser('H:/')))
    print(' Open file :', file_path)
    if file_path is not None:

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

def open_point():
    global file_text
    print(" load pcd File path :" + file_text)
    pcd = o3d.io.read_point_cloud(file_text)
    print(pcd)  #  Number of output point cloud points 
    print(np.asarray(pcd.points))  #  Output the 3D coordinates of the point 
    print(' Give all the dots a uniform color , The color is in RGB Space has to be [0,1] The value in the range ')
    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 title ')  #  title 
    window.geometry('500x300')  #  Window size 
    text1 = tk.Text(window, width=50, height=10, bg='orange', font=('Arial', 12))
    text1.pack()

    vis1 = init_window()
    bt1 = tk.Button(window, text=' choice pcd file ', width=15, height=2, command=choose_pcd)
    bt1.pack()

    bt2 = tk.Button(window, text=' Open point cloud ', width=15, height=2, command=open_point)
    bt2.pack()

    window.mainloop()  #  Show 




原网站

版权声明
本文为[Programmers evolve without losing their hair!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070135403361.html