简体   繁体   English

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

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

I want to create a real-time, point plotting GUI. 我想创建一个实时的点图GUI。 I am using the Scanse Sweep LiDAR, and at each sweep of this LiDAR (working between 1 - 10Hz) I receive approximately 1000 points (x, y) describing the LiDARs surrounding. 我正在使用Scanse Sweep LiDAR,在此LiDAR的每次扫描中(工作在1-10Hz之间),我收到大约1000个点(x,y),描述了周围的LiDAR。 This is a 2D LiDAR. 这是2D LiDAR。

I have looked everywhere and tried countless of code snippets for pyqtgraph, but either it crashes, is super slow or doesn't work at all. 我到处都看过了,尝试了无数的pyqtgraph代码片段,但是它崩溃了,速度很慢,或者根本无法工作。

Is there a straight-forward way of creating a plotter window and upon each new scan/data delivery, push those points to the plotter window? 是否有直接创建绘图仪窗口的方法,并且在每次进行新的扫描/数据传送时,将这些推到绘图仪窗口?

Thankful for any kind of help 感谢任何帮助

It is unclear to me what exactly you want to do, so I assume that you want to make a scatter plot with a 1000 points that are refreshed 10 times a second. 我不清楚您到底想做什么,所以我假设您想制作一个散点图,该点具有1000点,每秒刷新10次。 Next time please include your code so that we can reproduce your issues and see what you want to achieve. 下次请提供您的代码,以便我们重现您的问题并查看您要实现的目标。

In my experience PyQtGraph is the fastest option in Python. 以我的经验,PyQtGraph是Python中最快的选择。 It can easily plot a 1000 points at 10 Hz. 它可以轻松地在10 Hz处绘制1000点。 See the example below. 请参见下面的示例。

#!/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()

The way it works is as follows. 其工作方式如下。 By plotting an empty list a PlotDataItem is created. 通过绘制一个空列表,将创建一个PlotDataItem This represents a collection of points. 这代表了点的集合。 When new data points arrive, the setData method is used to set them as the data of the PlotDataItem, which removes the old points. 当新的数据点到达时,将使用setData方法将它们设置为PlotDataItem的数据,该数据将删除旧的点。

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

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