2010-03-22 06:21:56 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Demonstrates very basic use of ImageItem to display image data inside a ViewBox.
|
|
|
|
"""
|
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
2012-12-26 22:51:52 +00:00
|
|
|
import initExample
|
2011-04-05 14:35:50 +00:00
|
|
|
|
2012-03-02 03:58:02 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
2011-04-05 14:35:50 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
2012-03-02 03:58:02 +00:00
|
|
|
import pyqtgraph.ptime as ptime
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2021-01-27 18:59:07 +00:00
|
|
|
app = pg.mkQApp("ImageItem Example")
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
## Create window with GraphicsView widget
|
2013-02-25 04:09:03 +00:00
|
|
|
win = pg.GraphicsLayoutWidget()
|
|
|
|
win.show() ## show widget alone in its own window
|
|
|
|
win.setWindowTitle('pyqtgraph example: ImageItem')
|
|
|
|
view = win.addViewBox()
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
## lock the aspect ratio so pixels are always square
|
2010-03-22 06:21:56 +00:00
|
|
|
view.setAspectLocked(True)
|
|
|
|
|
|
|
|
## Create image item
|
2012-03-02 02:55:32 +00:00
|
|
|
img = pg.ImageItem(border='w')
|
2013-02-25 04:09:03 +00:00
|
|
|
view.addItem(img)
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
## Set initial view bounds
|
2012-03-02 02:55:32 +00:00
|
|
|
view.setRange(QtCore.QRectF(0, 0, 600, 600))
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
## Create random image
|
2012-03-02 02:55:32 +00:00
|
|
|
data = np.random.normal(size=(15, 600, 600), loc=1024, scale=64).astype(np.uint16)
|
2011-04-05 14:35:50 +00:00
|
|
|
i = 0
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
updateTime = ptime.time()
|
|
|
|
fps = 0
|
|
|
|
|
2021-03-01 05:45:00 +00:00
|
|
|
timer = QtCore.QTimer()
|
|
|
|
timer.setSingleShot(True)
|
|
|
|
# not using QTimer.singleShot() because of persistence on PyQt. see PR #1605
|
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
def updateData():
|
2012-03-02 02:55:32 +00:00
|
|
|
global img, data, i, updateTime, fps
|
2010-03-22 06:21:56 +00:00
|
|
|
|
|
|
|
## Display the data
|
2012-03-02 02:55:32 +00:00
|
|
|
img.setImage(data[i])
|
2011-04-05 14:35:50 +00:00
|
|
|
i = (i+1) % data.shape[0]
|
2011-06-14 23:47:52 +00:00
|
|
|
|
2021-03-01 05:45:00 +00:00
|
|
|
timer.start(1)
|
2012-03-02 02:55:32 +00:00
|
|
|
now = ptime.time()
|
|
|
|
fps2 = 1.0 / (now-updateTime)
|
|
|
|
updateTime = now
|
|
|
|
fps = fps * 0.9 + fps2 * 0.1
|
|
|
|
|
|
|
|
#print "%0.1f fps" % fps
|
2010-03-22 06:21:56 +00:00
|
|
|
|
2021-03-01 05:45:00 +00:00
|
|
|
timer.timeout.connect(updateData)
|
2011-06-14 23:47:52 +00:00
|
|
|
updateData()
|
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
## Start Qt event loop unless running in interactive mode.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|