问题
Hi everyone,
I'm writing a GUI for a camera and I'd like to have a widget with the live stream from the camera.
Following one of the examples, I'm doing it this way:
def updateview():
global img, camera
img.setImage(camera.most_recent_image(camera.detector_shape))
win = QtGui.QWidget()
# Image widget
imagewidget = pg.GraphicsLayoutWidget()
view = imagewidget.addViewBox()
view.setAspectLocked(True)
img = pg.ImageItem(border='w')
view.addItem(img)
view.setRange(QtCore.QRectF(0, 0, 512, 512))
layout = QtGui.QGridLayout()
win.setLayout(layout)
layout.addWidget(imagewidget, 1, 2, 3, 1)
win.show()
viewtimer = QtCore.QTimer()
viewtimer.timeout.connect(updateview)
viewtimer.start(0)
app.exec_()
viewtimer.stop()
This indeed works and I would be happy with it if it wasn't for the fact that I also need the intensity histogram on the side.
So I tried changing the first paragraphs like this:
def updateview():
global img, camera
img.setImage(camera.most_recent_image(camera.detector_shape),
autoHistogramRange=False)
win = QtGui.QWidget()
img = pg.ImageView()
layout = QtGui.QGridLayout()
win.setLayout(layout)
layout.addWidget(img, 1, 2, 3, 1)
This only works for a few frames (I can see the images changing and the histogram moving accordingly) and then the whole GUI freezes. Has anyone seen this behaviour?
Thanks in advanced,
Federico
回答1:
First: It is possible to use the histogram / contrast controls without ImageView. See: https://github.com/pyqtgraph/pyqtgraph/blob/develop/examples/imageAnalysis.py
Regarding the freezing: If I run your code generating random data rather than pulling from a camera, it runs just fine. I suspect the problem lies elsewhere. Are you perhaps using multiple threads incorrectly? You may need to post a more complete example, and do some testing to determine where the program is hanging up.
来源:https://stackoverflow.com/questions/24375266/pyqtgraph-live-video-stream-freezes-using-imageview