使用 pyqtgraph 和 LiDAR 快速实时绘制点 [英] Fast, Real-time plotting of points using pyqtgraph and a LiDAR
问题描述
我想创建一个实时的点绘图 GUI.我正在使用 Scanse Sweep LiDAR,并且在每次扫描该 LiDAR(在 1 - 10Hz 之间工作)时,我都会收到大约 1000 个描述周围 LiDAR 的点 (x, y).这是一个二维激光雷达.
I want to create a real-time, point plotting 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. This is a 2D LiDAR.
我到处寻找并尝试了无数的 pyqtgraph 代码片段,但要么崩溃,要么速度超慢,要么根本无法工作.
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.
是否有一种直接的方法来创建绘图仪窗口,并在每次新的扫描/数据传送时将这些点推到绘图仪窗口?
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?
感谢您的任何帮助
推荐答案
我不清楚你到底想做什么,所以我假设你想制作一个 1000 个点的散点图,每个点刷新 10 次第二.下次请包含您的代码,以便我们可以重现您的问题并查看您想要实现的目标.
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. Next time please include your code so that we can reproduce your issues and see what you want to achieve.
根据我的经验,PyQtGraph 是 Python 中最快的选项.它可以轻松地以 10 Hz 的频率绘制 1000 个点.请参阅下面的示例.
In my experience PyQtGraph is the fastest option in Python. It can easily plot a 1000 points at 10 Hz. 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()
它的工作方式如下.通过绘制一个空列表,一个 PlotDataItem 被创建.这表示点的集合.当新数据点到达时,使用setData
方法将它们设置为PlotDataItem 的数据,从而去除旧点.
The way it works is as follows. By plotting an empty list a PlotDataItem is created. 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.
这篇关于使用 pyqtgraph 和 LiDAR 快速实时绘制点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!