Commit 23265307 authored by Martin Drechsler's avatar Martin Drechsler

Now the roi analysis is enabled.

parent c644ab2b
This diff is collapsed.
......@@ -7,131 +7,157 @@ Created on Thu Jul 5 12:17:30 2018
from PyQt5.QtCore import QSettings
from PyQt5.QtWidgets import QAction, QFileDialog
from PyQt5.QtWidgets import QAction, QFileDialog, QInputDialog, QWidget
from threading import Thread
from webcamROI import roiWindow
#%%
def save(aos):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
settings.setValue(str(ao.name) + '_' + text, spinb.value())
#print(spinb.value() )
settings.endGroup()
print('saving')
def load(aos):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
settings.endGroup()
def first_load(aos):
try:
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
except:
print('Warning: no config.ini file in control_app folder. Pleace, be kindful and create one')
return
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
settings.endGroup()
def save_as(aos, window):
name = QFileDialog.getSaveFileName(window, 'Save File')
file = open(name[0], 'w+')
file.close()
settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
settings.setValue(str(ao.name) + '_' + text, spinb.value())
#print(spinb.value() )
settings.endGroup()
print('saving to %s' % name[0])
def open_from(aos, window):
name = QFileDialog.getOpenFileName(window, 'Save File')
settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
settings.endGroup()
def startWebcamsThread():
exec(open('C:\\Users\\Usuario\\Documents\\control_app\\webcams.py').read())
class myToolbarMenu(QWidget):
"""
This will create a toolbar menu
"""
def putWebcams(checked):
if checked:
t_webcams = Thread(target=startWebcamsThread, args=())
t_webcams.start()
else:
pass
def __init__(self, win, analog_control_signals):
super().__init__()
self.MainGuiWindow = win
self.aos = analog_control_signals
self.first_load(self.aos)
self.incorporate_toolbar(self.MainGuiWindow, self.aos)
self.createAosDict()
def openRoi():
print('opening roi window')
#t_roi = Thread(target=startRoiThread, args=())
#t_roi.start()
startRoiThread()
def startRoiThread():
roiW = roiWindow()
roiW.w.show()
def createAosDict(self):
analogs = self.aos
self.aosDicc = {}
for i in range(len(analogs)):
self.aosDicc[analogs[i].name] = analogs[i]
def incorporate_toolbar(self, win, analog_control_signals):
menubar = win.menuBar()
def incorporate_toolbar(win, analog_control_signals):
menubar = win.menuBar()
saveAct = QAction('Save', win)
loadAct = QAction('Load', win)
saveAsAct = QAction('Save as' , win)
openFromAct = QAction('open from', win)
win.statusBar()
menubar = win.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(saveAct)
fileMenu.addAction(loadAct)
fileMenu.addAction(saveAsAct)
fileMenu.addAction(openFromAct)
viewMenu = menubar.addMenu('Monitor')
viewWebcams = QAction('View webcams', win, checkable=True)
viewWebcams.setChecked(False)
viewMenu.addAction(viewWebcams)
roiMenu = menubar.addMenu('Roi')
plotRoi = QAction('Open roi plot', win)
roiMenu.addAction(plotRoi)
saveAct.triggered.connect(lambda: self.save(analog_control_signals))
loadAct.triggered.connect(lambda: self.load(analog_control_signals))
saveAsAct.triggered.connect(lambda: self.save_as(analog_control_signals, win))
openFromAct.triggered.connect(lambda: self.open_from(analog_control_signals, win))
viewWebcams.toggled.connect(lambda: self.putWebcams(viewWebcams.isChecked()) )
plotRoi.triggered.connect(self.openRoi)
saveAct = QAction('Save', win)
loadAct = QAction('Load', win)
saveAsAct = QAction('Save as' , win)
openFromAct = QAction('open from', win)
win.statusBar()
menubar = win.menuBar()
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(saveAct)
fileMenu.addAction(loadAct)
fileMenu.addAction(saveAsAct)
fileMenu.addAction(openFromAct)
viewMenu = menubar.addMenu('Monitor')
viewWebcams = QAction('View webcams', win, checkable=True)
viewWebcams.setChecked(False)
viewMenu.addAction(viewWebcams)
roiMenu = menubar.addMenu('Roi')
plotRoi = QAction('Open roi plot', win)
roiMenu.addAction(plotRoi)
saveAct.triggered.connect(lambda: save(analog_control_signals))
loadAct.triggered.connect(lambda: load(analog_control_signals))
saveAsAct.triggered.connect(lambda: save_as(analog_control_signals, win))
openFromAct.triggered.connect(lambda: open_from(analog_control_signals, win))
viewWebcams.toggled.connect(lambda: putWebcams(viewWebcams.isChecked()) )
plotRoi.triggered.connect(openRoi)
\ No newline at end of file
def save(self, aos):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
settings.setValue(str(ao.name) + '_' + text, spinb.value())
#print(spinb.value() )
settings.endGroup()
print('saving')
def load(self, aos):
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
settings.endGroup()
def first_load(self, aos):
try:
settings = QSettings('C:\\Users\\Usuario\\Documents\\control_app\\config.ini', QSettings.IniFormat)
except:
print('Warning: no config.ini file in control_app folder. Pleace, be kindful and create one')
return
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
settings.endGroup()
def save_as(self, aos, window):
name = QFileDialog.getSaveFileName(window, 'Save File')
file = open(name[0], 'w+')
file.close()
settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
settings.setValue(str(ao.name) + '_' + text, spinb.value())
#print(spinb.value() )
settings.endGroup()
print('saving to %s' % name[0])
def open_from(self, aos, window):
name = QFileDialog.getOpenFileName(window, 'Save File')
settings = QSettings(name[0], QSettings.IniFormat)
settings.beginGroup('Ventana')
for ao in aos:
spin_boxes = ao.spin_boxes
for text, spinb in spin_boxes:
spin = settings.value(str(ao.name) + '_' + text)
spinb.setValue( float(spin) )
settings.endGroup()
def startWebcamsThread(self):
exec(open('C:\\Users\\Usuario\\Documents\\control_app\\webcams.py').read())
def putWebcams(self, checked):
if checked:
t_webcams = Thread(target=self.startWebcamsThread, args=())
t_webcams.start()
else:
pass
def openRoi(self):
print('opening roi window')
ao = self.getChoiceForRoi()
self.startRoiThread(ao)
def startRoiThread(self, ao):
self.roiW = roiWindow(ao)
self.roiW.w.show()
def getChoiceForRoi(self):
items = self.aosDicc.keys()
item, okPressed = QInputDialog.getItem(self, "Get item","Color:", items, 0, False)
if okPressed and item:
return self.aosDicc[item]
\ No newline at end of file
......@@ -11,16 +11,21 @@ import numpy as np
import pyqtgraph as pg
import cv2
from PyQt5.QtCore import QTimer
#from myWidgets import anal_control_signal
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox, QPushButton, QGraphicsProxyWidget
class roiWindow(QMainWindow):
def __init__(self):
def __init__(self, aoScan):
super().__init__()
self.aoScan = aoScan
print(self.aoScan.name, self.aoScan.sb.val)
self.cap = cv2.VideoCapture(1)
......@@ -30,7 +35,7 @@ class roiWindow(QMainWindow):
self.rois = []
#self.rois.append(pg.EllipseROI([110, 10], [30, 20], pen=(3,9)))
self.rois.append(pg.TestROI([0, 0], [20, 20], pen=(0,9)))
self.rois.append(pg.TestROI([500, 500], [100, 100], pen=(0,9)))
self.initUI()
......@@ -48,23 +53,38 @@ class roiWindow(QMainWindow):
self.imgTimer = QTimer()
self.imgTimer.timeout.connect(self.updateImage)
self.imgTimer.start(10)
self.imgTimer.start(2)
self.im2 = pg.ImageItem()
self.v2 = self.w.addViewBox(1,0)
self.v2.addItem(self.im2)
#plot real time
self.p = self.w.addPlot(row = 3, col = 0, title="Updating plot")
self.p.setRange(QtCore.QRectF(0, -10, 5000, 20))
self.p.setAutoPan(y=True)
self.p.setRange(xRange = (0, self.n), yRange = (0, 255))
self.curve = self.p.plot(pen='y')
self.pv = self.w.addPlot(row = 4, col = 0, title = "Updating plot")
self.pv.setRange(QtCore.QRectF(0, -10, 5000, 20))
self.pv.setAutoPan(y=True)
self.curveVoltage = self.pv.plot(pen='y')
self.voltageDataX = []
self.voltageDataY = []
self.aoScan.ScanTimer.timeout.connect(self.updateVoltagePlotvsI)
self.eraseButton = QPushButton('Erase')
self.eraseButton.clicked.connect(self.erasePlot)
proxy = QGraphicsProxyWidget()
proxy.setWidget(self.eraseButton)
self.pv.addItem(proxy,row=1,col=1)
self.lastRoi = None
self.newData = 0
## Add each ROI to the scene and link its data to a plot curve with the same color
for r in self.rois:
......@@ -72,8 +92,38 @@ class roiWindow(QMainWindow):
r.sigRegionChanged.connect(self.updateRoi)
self.w.show()
self.w.closeEvent = self.myCloseEvent
def updateVoltagePlotvsI(self):
#plot against voltage
self.voltageDataX = np.append(self.voltageDataX, self.aoScan.scan_step)
self.voltageDataY = np.append(self.voltageDataY, self.newData)
#○print(' Roi: ', self.voltageDataX[-1], self.voltageDataY[-1])
self.pv.setRange(xRange = (float(self.aoScan.scan_sb_start.val), float(self.aoScan.scan_sb_stop.val)), yRange = (0, 255))
self.curveVoltage.setData(self.voltageDataX, self.voltageDataY)
def erasePlot(self):
self.voltageDataX = []
self.voltageDataY = []
def myCloseEvent(self, event):
# this overrides the closeEvent method
reply = QMessageBox.question(self, 'Message',
"Quit roi analysis screen?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
self.imgTimer.stop()
self.cap.release()
cv2.destroyAllWindows()
event.accept()
else:
event.ignore()
def capture(self):
ret, frame = self.cap.read()
#frame = cv2.resize(frame, None, fx = 0.5, fy = 0.5, interpolation = cv2.INTER_CUBIC)
......@@ -91,8 +141,8 @@ class roiWindow(QMainWindow):
self.lastRoi = roi
roiSlice = roi.getArrayRegion(self.im1.image, img=self.im1)
self.im2.setImage(roiSlice)
newData = np.mean(roiSlice)
self.data[self.i] = newData
self.newData = np.mean(roiSlice)
self.data[self.i] = self.newData
self.i = np.mod(self.i + 1, len(self.data))
self.curve.setData(self.data)
......@@ -101,10 +151,12 @@ class roiWindow(QMainWindow):
self.curve.setData(data)
#app.processEvents() ## force complete redraw for every plot
if __name__ == '__main__':
ao = anal_control_signal('ao', 0)
app = QApplication(sys.argv)
ex = roiWindow()
ex = roiWindow(ao)
sys.exit(app.exec_())
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment