pyqtgraph实时图像流多处理

时间:2018-08-28 11:55:23

标签: python multiprocessing 2d real-time pyqtgraph

我打算对实时流化的数据进行可视化处理。数据实际上是图像(记录流),但是可以说无限长。我希望以fifo方式显示它-移动窗口。可视化必须在单独的过程中完成。

我在考虑同步机制-从生产者到消费者,有一些可能的方式-fifo,循环缓冲区,列表列表以及锁定机制,最后是QtProcess-> transfer(在https://stackoverflow.com/a/17953175/10169642中使用)。我决定了最后一个,因为它似乎可以与pyqtgraph很好地同步,并且复杂度较低。

以下链接包含执行图像不断更新的代码。 http://www.pyqtgraph.org/downloads/0.10.0/pyqtgraph-0.10.0-deb/pyqtgraph-0.10.0/examples/ImageItem.py

下面的代码段应该模拟刷新图像的3个步骤(三个连续的帧)。它也不会切断尾巴-它会稳定增加。这是合并上面链接中给出的两个片段的效果。

from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import numpy as np
pg.mkQApp()


# Create remote process with a plot window
import pyqtgraph.multiprocess as mp
proc = mp.QtProcess()
rpg = proc._import('pyqtgraph')
win = rpg.GraphicsLayoutWidget()
win.show()  ## show widget alone in its own window
win.setWindowTitle('pyqtgraph example: ImageItem')
view = win.addViewBox()

## lock the aspect ratio so pixels are always square
view.setAspectLocked(True)

## Create image item
img = rpg.ImageItem(border='w')
view.addItem(img)

## Set initial view bounds
view.setRange(QtCore.QRectF(0, 0, 10, 10))

## Create set of random images
dataInit = np.random.normal(size=(15, 10, 10), loc=1024, scale=64).astype(np.uint16)
# create an empty list in the remote process
data = proc.transfer([])
## We use the special argument _callSync='off' because we do
## not want to wait for a return value.
data.extend(dataInit[0], _callSync='off')

img.setImage(data)

data.extend(dataInit[1], _callSync='off')

img.setImage(data)

data.extend(dataInit[2], _callSync='off')

img.setImage(data)

结果:

  

文件>“ .... / streaming_plot_4_multiprocess.py”,第35行,在      img.setImage(data)

     

文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-> packages \ pyqtgraph \ multiprocess \ remoteproxy.py”,第918行,位于调用中      返回self._handler.callObj(obj = self,args = args,kwds = kwds,** opts)

     

文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-> packages \ pyqtgraph \ multiprocess \ remoteproxy.py”,行567,在callObj中      返回self.send(request ='callObj',opts = dict(obj = obj,args = args,> kwds = kwds),byteData = byteMsgs,** opts)

     

文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-> packages \ pyqtgraph \ multiprocess \ remoteproxy.py”,行470,在发送中      返回req.result()

     

文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-> packages \ pyqtgraph \ multiprocess \ remoteproxy.py”,结果为636行      而不是self.hasResult():

     

hasResult中的文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-> packages \ pyqtgraph \ multiprocess \ remoteproxy.py”,行654      self.result(block = False)

     

文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-> packages \ pyqtgraph \ multiprocess \ remoteproxy.py”,行647,结果      self._result = self.proc.getResult(self.reqId)##如果> result尚不可用,则会引发NoResultError

     

getResult中第508行的文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-> packages \ pyqtgraph \ multiprocess \ remoteproxy.py”      提高经验

     

AttributeError:“列表”对象没有属性“视图”

0 个答案:

没有答案