Answer the question
In order to leave comments, you need to log in
PyQtGraph. Increase fps when displaying 4.2 MPixels image?
Hello!
Wrote an application for displaying video from a 4.2 MPixels scientific camera. However, fps for this resolution is about 6. Examples of SpeedTest_Video for pyqtgraph at large values give the same result. Does anyone have any ideas how to speed up the whole thing (fine tuning is important in the work)? Newbie in programming.
To test the application, the image is replaced by the intensity function, the speed of creating the grab_image() array in this code coincides with the speed of obtaining an image from a camera with a minimum exposure. A color card is required. The app has buttons and more, but I don't draw them for testing purposes.
import sys
import matplotlib.pyplot as plt
import numpy as np
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
from PyQt5.QtWidgets import QMainWindow
from MineGUI import Ui_Dialog
from pyqtgraph.ptime import time
class MainWindow(QMainWindow, Ui_Dialog):
def __init__(self, parent=None, *args, **kwargs):
QMainWindow.__init__(self)
self.setupUi(self)
def main():
# Init main window window
app = QtGui.QApplication([])
main = MainWindow()
main.show()
# Add ViewBox for Image
view = pg.ViewBox()
main.imshow.setCentralItem(view) # (main.imshow = pg.GraphicsView(Dialog) from MineGUI)
# Add Image Item and set colormap
img = pg.ImageItem()
cmap = pg.ColorMap(bit, colmap)
lut = cmap.getLookupTable(0.0, 1.0, 255)
img.setLookupTable(lut)
img.setAutoDownsample(True)
img.setBorder('b')
view.addItem(img)
timer = QtCore.QTimer()
def setText(qo):
main.exposValue.setText(str(qo)) #(main.exposValue = QtWidgets.QLabel(Dialog) from MineGUI)
def grab_image():
wx = 720 + np.random.rand(1) * 20
wy = 650 + np.random.rand(1) * 30
return intensity(x, wx, wy)
def intensity(x, wx, wy):
zx = np.exp(-2 * (x[None, :] - 1000) ** 2 / wx ** 2)
zy = np.exp(-2 * (x[:, None] - 1000) ** 2 / wy ** 2)
return (zx * zy)
global lastTime, fps
lastTime = time()
fps = None
x = np.arange(0, 2048, 1)
def update():
global lastTime, fps, data
data = grab_image()
img.setImage(data)
now = time()
dt = now - lastTime
lastTime = now
if fps is None:
fps = 1.0 / dt
else:
s = np.clip(dt * 3., 0, 1)
fps = fps * (1 - s) + (1.0 / dt) * s
setText('%0.2f fps' % fps)
start = time()
app.processEvents()
print(time() - start)
timer.timeout.connect(update)
timer.start(0)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
bit = np.arange(0, 257, 1)/256
colmap = np.array(255 * plt.cm.nipy_spectral(bit), dtype=np.ubyte)
main()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question