《pyqt+open3d》open3d可视化界面集成到qt中

《pyqt+open3d》open3d可视化界面集成到qt中

一、效果显示

二、代码

参考链接

main.py

python 复制代码
import sys
import open3d as o3d
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
from PyQt5.QtGui import QWindow
from PyQt5.QtCore import QTimer
import win32gui
import MainWindow

class MainWindows(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindows, self).__init__(parent)
        self.ui = MainWindow.Ui_MainWindow()
        self.ui.setupUi(self)
        self.vis = o3d.visualization.Visualizer()
        self.vis.create_window(visible=False)  # visible=False窗口不显示,避免启动时一闪而过
        self.winid = win32gui.FindWindow('GLFW30', None)
        self.sub_window = QWindow.fromWinId(self.winid)
        self.displayer = QWidget.createWindowContainer(self.sub_window)
        self.ui.gridLayout.addWidget(self.displayer)
        self.clock = QTimer(self)
        self.clock.timeout.connect(self.draw_update)
        self.clock.start(20)
        self.draw_test()

    def draw_test(self):
        pcd = o3d.io.read_point_cloud('output1.ply')  # 点云路径
        self.vis.add_geometry(pcd)
        self.vis.update_geometry(pcd)

    def draw_update(self):
        self.vis.poll_events()
        self.vis.update_renderer()

    def __del__(self):
        # self.clock.stop()      #这一行其实并不需要
        self.vis.destroy_window()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MainWindows()
    window.show()
    sys.exit(app.exec_())

mainWindow.py

python 复制代码
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'MainWindow.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout_2 = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout_2.setObjectName("gridLayout_2")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))

ui文件在下载链接中

三、资源下载

下载链接

相关推荐
十启树4 小时前
Qt 中实现炫酷的开机启动动画
qt
一叶之秋14121 天前
QT背景介绍与环境搭建
开发语言·qt
QT 小鲜肉1 天前
【QT/C++】Qt网络编程进阶:UDP通信和HTTP请求的基本原理和实际应用(超详细)
c语言·网络·c++·笔记·qt·http·udp
四维碎片1 天前
【Qt】大数据量表格刷新优化--只刷新可见区域
开发语言·qt
一叶之秋14121 天前
Qt开发初识
开发语言·qt
梵尔纳多1 天前
ffmpeg 使用滤镜实现播放倍速
c++·qt·ffmpeg
QT 小鲜肉1 天前
【QT/C++】Qt网络编程进阶:TCP网络编程的基本原理和实际应用(超详细)
c语言·开发语言·网络·c++·qt·学习·tcp/ip
Tony小周2 天前
使用QKeyEvent keyPress(QEvent::KeyPress, key模拟键盘发送事件,会导致主程序卡死
嵌入式硬件·qt
Larry_Yanan2 天前
QML学习笔记(五十)QML与C++交互:QML中单例C++对象
开发语言·c++·笔记·qt·学习·ui·交互
zhmhbest2 天前
Qt 全球峰会 2025:中国站速递 —— 技术中立,拥抱更大生态
开发语言·qt·系统架构