Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
total_control_app
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Drechsler
total_control_app
Commits
23265307
Commit
23265307
authored
Aug 14, 2018
by
Martin Drechsler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now the roi analysis is enabled.
parent
c644ab2b
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
382 additions
and
298 deletions
+382
-298
myGUI.py
myGUI.py
+171
-165
myToolbar.py
myToolbar.py
+145
-119
webcamROI.py
webcamROI.py
+66
-14
No files found.
myGUI.py
View file @
23265307
This diff is collapsed.
Click to expand it.
myToolbar.py
View file @
23265307
...
...
@@ -7,13 +7,69 @@ 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
#%%
class
myToolbarMenu
(
QWidget
):
"""
This will create a toolbar menu
"""
def
save
(
aos
):
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
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
()
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
)
def
save
(
self
,
aos
):
settings
=
QSettings
(
'C:
\\
Users
\\
Usuario
\\
Documents
\\
control_app
\\
config.ini'
,
QSettings
.
IniFormat
)
settings
.
beginGroup
(
'Ventana'
)
for
ao
in
aos
:
...
...
@@ -25,7 +81,7 @@ def save(aos):
settings
.
endGroup
()
print
(
'saving'
)
def
load
(
aos
):
def
load
(
self
,
aos
):
settings
=
QSettings
(
'C:
\\
Users
\\
Usuario
\\
Documents
\\
control_app
\\
config.ini'
,
QSettings
.
IniFormat
)
settings
.
beginGroup
(
'Ventana'
)
for
ao
in
aos
:
...
...
@@ -35,7 +91,7 @@ def load(aos):
spinb
.
setValue
(
float
(
spin
)
)
settings
.
endGroup
()
def
first_load
(
aos
):
def
first_load
(
self
,
aos
):
try
:
settings
=
QSettings
(
'C:
\\
Users
\\
Usuario
\\
Documents
\\
control_app
\\
config.ini'
,
QSettings
.
IniFormat
)
except
:
...
...
@@ -51,7 +107,7 @@ def first_load(aos):
settings
.
endGroup
()
def
save_as
(
aos
,
window
):
def
save_as
(
self
,
aos
,
window
):
name
=
QFileDialog
.
getSaveFileName
(
window
,
'Save File'
)
file
=
open
(
name
[
0
],
'w+'
)
...
...
@@ -67,7 +123,7 @@ def save_as(aos, window):
settings
.
endGroup
()
print
(
'saving to
%
s'
%
name
[
0
])
def
open_from
(
aos
,
window
):
def
open_from
(
self
,
aos
,
window
):
name
=
QFileDialog
.
getOpenFileName
(
window
,
'Save File'
)
settings
=
QSettings
(
name
[
0
],
QSettings
.
IniFormat
)
...
...
@@ -79,59 +135,29 @@ def open_from(aos, window):
spinb
.
setValue
(
float
(
spin
)
)
settings
.
endGroup
()
def
startWebcamsThread
(
):
def
startWebcamsThread
(
self
):
exec
(
open
(
'C:
\\
Users
\\
Usuario
\\
Documents
\\
control_app
\\
webcams.py'
)
.
read
())
def
putWebcams
(
checked
):
def
putWebcams
(
self
,
checked
):
if
checked
:
t_webcams
=
Thread
(
target
=
startWebcamsThread
,
args
=
())
t_webcams
=
Thread
(
target
=
self
.
startWebcamsThread
,
args
=
())
t_webcams
.
start
()
else
:
pass
def
openRoi
(
):
def
openRoi
(
self
):
print
(
'opening roi window'
)
#t_roi = Thread(target=startRoiThread, args=())
#t_roi.start()
startRoiThread
()
def
startRoiThread
():
roiW
=
roiWindow
()
roiW
.
w
.
show
()
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'
)
ao
=
self
.
getChoiceForRoi
()
self
.
startRoiThread
(
ao
)
fileMenu
.
addAction
(
saveAct
)
fileMenu
.
addAction
(
loadAct
)
fileMenu
.
addAction
(
saveAsAct
)
fileMenu
.
addAction
(
openFromAct
)
def
startRoiThread
(
self
,
ao
):
self
.
roiW
=
roiWindow
(
ao
)
self
.
roiW
.
w
.
show
()
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
)
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
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
webcamROI.py
View file @
23265307
...
...
@@ -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
,
2
0
],
pen
=
(
0
,
9
)))
self
.
rois
.
append
(
pg
.
TestROI
([
500
,
500
],
[
100
,
10
0
],
pen
=
(
0
,
9
)))
self
.
initUI
()
...
...
@@ -48,13 +53,13 @@ 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
)
...
...
@@ -62,16 +67,61 @@ class roiWindow(QMainWindow):
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
.
lastRoi
=
None
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
:
self
.
v
.
addItem
(
r
)
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
):
...
...
@@ -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
)
...
...
@@ -103,8 +153,10 @@ class roiWindow(QMainWindow):
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment