繁体   English   中英

使用pyqtgraph和LiDAR快速,实时地绘制点

[英]Fast, Real-time plotting of points using pyqtgraph and a LiDAR

我想创建一个实时的点图GUI。 我正在使用Scanse Sweep LiDAR,在此LiDAR的每次扫描中(工作在1-10Hz之间),我收到大约1000个点(x,y),描述了周围的LiDAR。 这是2D LiDAR。

我到处都看过了,尝试了无数的pyqtgraph代码片段,但是它崩溃了,速度很慢,或者根本无法工作。

是否有直接创建绘图仪窗口的方法,并且在每次进行新的扫描/数据传送时,将这些推到绘图仪窗口?

感谢任何帮助

我不清楚您到底想做什么,所以我假设您想制作一个散点图,该点具有1000点,每秒刷新10次。 下次请提供您的代码,以便我们重现您的问题并查看您要实现的目标。

以我的经验,PyQtGraph是Python中最快的选择。 它可以轻松地在10 Hz处绘制1000点。 请参见下面的示例。

#!/usr/bin/env python

from PyQt5 import QtCore, QtWidgets
import pyqtgraph as pg
import numpy as np


class MyWidget(pg.GraphicsWindow):

    def __init__(self, parent=None):
        super().__init__(parent=parent)

        self.mainLayout = QtWidgets.QVBoxLayout()
        self.setLayout(self.mainLayout)

        self.timer = QtCore.QTimer(self)
        self.timer.setInterval(100) # in milliseconds
        self.timer.start()
        self.timer.timeout.connect(self.onNewData)

        self.plotItem = self.addPlot(title="Lidar points")

        self.plotDataItem = self.plotItem.plot([], pen=None, 
            symbolBrush=(255,0,0), symbolSize=5, symbolPen=None)


    def setData(self, x, y):
        self.plotDataItem.setData(x, y)


    def onNewData(self):
        numPoints = 1000  
        x = np.random.normal(size=numPoints)
        y = np.random.normal(size=numPoints)
        self.setData(x, y)


def main():
    app = QtWidgets.QApplication([])

    pg.setConfigOptions(antialias=False) # True seems to work as well

    win = MyWidget()
    win.show()
    win.resize(800,600) 
    win.raise_()
    app.exec_()

if __name__ == "__main__":
    main()

其工作方式如下。 通过绘制一个空列表,将创建一个PlotDataItem 这代表了点的集合。 当新的数据点到达时,将使用setData方法将它们设置为PlotDataItem的数据,该数据将删除旧的点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM