PyQt加载 显示点云,已经有三种方式,使用 open3d; 使用 vtk; 使用 pcl;
下面是使用 open3d:
python
import sys
import open3d as o3d
import numpy as np
import pyqtgraph.opengl as gl
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget, QFileDialog
from pyqtgraph.opengl import GLViewWidget
from Ui_widget import Ui_Form
class PyQtGraphicDemo(QWidget, Ui_Form):
def __init__(self, parent=None):
super(PyQtGraphicDemo, self).__init__(parent)
self.setupUi(self)
self.graphicsView = GLViewWidget(self)
self.pushButton.clicked.connect(self.showCloud)
self.verticalLayout = QVBoxLayout(self)
self.verticalLayout.addWidget(self.graphicsView)
self.verticalLayout.addWidget(self.pushButton)
self.setLayout(self.verticalLayout)
def showCloud(self):
fileName, filetype = QFileDialog.getOpenFileName(self, "请选择点云:", '.', "cloud Files(*pcd *ply)")
if fileName != '':
pcd = o3d.io.read_point_cloud(fileName) #读取点云
np_points = np.asarray(pcd.points) #获取Numpy数组
plot = gl.GLScatterPlotItem() #创建显示对象
plot.setData(pos=np_points, color=(1, 1, 1, 1), size=0.001, pxMode=False) #设置显示数据
self.graphicsView.addItem(plot) #显示点云
if __name__ == '__main__':
app = QApplication(sys.argv)
window = PyQtGraphicDemo()
window.show()
sys.exit(app.exec_())