[英]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.