|
| 1 | +from __future__ import (print_function, unicode_literals, division, |
| 2 | + absolute_import) |
| 3 | + |
| 4 | +import time |
| 5 | +import pyqtgraph as pg |
| 6 | +from pyqtgraph.Qt import QtCore, QtGui |
| 7 | + |
| 8 | +from pydc1394 import Camera |
| 9 | + |
| 10 | + |
| 11 | +class CameraPlot: |
| 12 | + def __init__(self, camera): |
| 13 | + self.camera = camera |
| 14 | + self.init_win() |
| 15 | + self.init_camera() |
| 16 | + |
| 17 | + def init_win(self): |
| 18 | + self.win = QtGui.QMainWindow() |
| 19 | + self.win.show() |
| 20 | + self.win.resize(600, 400) |
| 21 | + self.win.setWindowTitle("pydc1394 + pyqtgraph") |
| 22 | + self.img = pg.ImageView() |
| 23 | + self.win.setCentralWidget(self.img) |
| 24 | + |
| 25 | + def init_camera(self): |
| 26 | + print("Vendor:", self.camera.vendor) |
| 27 | + print("Model:", self.camera.model) |
| 28 | + print("GUID:", self.camera.guid) |
| 29 | + print("Mode:", self.camera.mode) |
| 30 | + print("Framerate: ", self.camera.rate) |
| 31 | + print("Available modes", [mode.name for mode in self.camera.modes]) |
| 32 | + print("Available features", self.camera.features) |
| 33 | + #modes = self.camera.modes |
| 34 | + #self.camera.mode = modes[0] |
| 35 | + |
| 36 | + def start_camera(self): |
| 37 | + self.camera.start_capture() |
| 38 | + self.camera.start_video() |
| 39 | + |
| 40 | + def process_images(self): |
| 41 | + QtCore.QTimer.singleShot(50, self.process_images) |
| 42 | + frame = None |
| 43 | + while True: |
| 44 | + frame_ = self.camera.dequeue(poll=True) |
| 45 | + if frame_ is not None: |
| 46 | + if frame is not None: |
| 47 | + frame.enqueue() |
| 48 | + frame = frame_ |
| 49 | + else: |
| 50 | + break |
| 51 | + if frame is None: |
| 52 | + return |
| 53 | + im = frame.copy().T |
| 54 | + frame.enqueue() |
| 55 | + self.img.setImage(im, autoRange=False, autoLevels=False, |
| 56 | + autoHistogramRange=False) |
| 57 | + |
| 58 | + def stop_camera(self): |
| 59 | + self.camera.stop_video() |
| 60 | + self.camera.stop_capture() |
| 61 | + |
| 62 | + def deinit_camera(self): |
| 63 | + pass |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == "__main__": |
| 67 | + app = QtGui.QApplication([]) |
| 68 | + cam = CameraPlot(Camera()) |
| 69 | + try: |
| 70 | + cam.start_camera() |
| 71 | + time.sleep(.5) |
| 72 | + cam.process_images() |
| 73 | + cam.img.autoRange() |
| 74 | + cam.img.autoLevels() |
| 75 | + QtGui.QApplication.instance().exec_() |
| 76 | + finally: |
| 77 | + cam.stop_camera() |
| 78 | + cam.deinit_camera() |
0 commit comments