-
Notifications
You must be signed in to change notification settings - Fork 1
/
colormapping.py
99 lines (84 loc) · 2.61 KB
/
colormapping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
Programe to light the C.elegans
"""
from pyqtgraph.Qt import QtGui, QtCore, USE_PYQT5
import numpy as np
import pyqtgraph as pg
import pyqtgraph.ptime as ptime
import homeui
import camera2c
import map
#import maptest
## Main Widow Setting
#QtGui.QApplication.setGraphicsSystem('raster')
app = QtGui.QApplication([])
win = QtGui.QMainWindow()
ui = homeui.Ui_MainWindow() # set ui
ui.setupUi(win)
win.setWindowTitle('Light for Life -- iGEM 2017')
win.show()
#map1=maptest()
#win.addWindow(map1)
#ui.graphicsView.useOpenGL()
vb = pg.ViewBox()
ui.graphicsView.setCentralItem(vb)
vb.setAspectLocked()
img = pg.ImageItem()
vb.addItem(img)
## ROI setting
rois = []
# add default roi
for i in [0,1,2,3]:
y0=70+i*30
rois.append(pg.RectROI([400,y0],[20,20]))
vb.addItem(rois[i])
bg = pg.LineROI([0,0], [0,-200],width=5)
vb.addItem(bg)
# camera2c Player
ptr = 0
lastTime = ptime.time()
fps = None
def update():
global ui, ptr, lastTime, fps, img
# Transfer the orign postion and color of ROI and edge
if ui.pushButton_roi.isChecked():
wormmap = np.zeros((4,6))
for i in [0,1,2,3]:
#print np.transpose(rois[i].parentBounds().getRect())
wormmap[i, 0:4] = np.transpose(rois[i].parentBounds().getRect())
wormmap[0, 4:6]= [ui.spinBox_0_red.value(),ui.spinBox_0_blue.value()]
wormmap[1, 4:6]= [ui.spinBox_1_red.value(),ui.spinBox_1_blue.value()]
wormmap[2, 4:6]= [ui.spinBox_2_red.value(),ui.spinBox_2_blue.value()]
wormmap[3, 4:6]= [ui.spinBox_3_red.value(),ui.spinBox_3_blue.value()]
map.setRoi(bg.parentBounds().getRect(),wormmap)
# Update Image
if ui.checkBox_sti.isChecked():
map.updateImage()
#camera2c.setExpoTime(ui.spinBox_expo.value()/1000.000)
if ui.radioButton_capture.isChecked():
img.setImage(camera2c.seq_capt(ui.spinBox_Interval.value()/1000.00))
elif ui.radioButton_pre.isChecked():
img.setImage(camera2c.live())
else:
img.setImage(camera2c.live())
ptr += 1
now = ptime.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
print('%0.2f fps' % fps)
app.processEvents() ## force complete redraw for every plot
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(0)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()