-
Notifications
You must be signed in to change notification settings - Fork 0
/
pvg_panel_two.py
240 lines (185 loc) · 9.43 KB
/
pvg_panel_two.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# untitled.py
#
# Copyright 2011 Giorgio Gilestro <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import wx, os
from pvg_common import previewPanel, options
class panelLiveView(wx.Panel):
"""
Panel Number 2
Live view of selected camera
"""
def __init__(self, parent):
"""
"""
wx.Panel.__init__(self, parent, wx.ID_ANY)
self.monitor_number = options.GetOption("Monitors")
self.fs_size = options.GetOption("FullSize")
self.monitor_name = ''
self.fsPanel = previewPanel(self, size=self.fs_size)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4 = wx.BoxSizer(wx.VERTICAL)
#Static box1: monitor input
sb_1 = wx.StaticBox(self, -1, "Select Monitor")#, size=(250,-1))
self.sbSizer_1 = wx.StaticBoxSizer (sb_1, wx.VERTICAL)
self.MonitorList = ['Monitor %s' % (int(m) + 1) for m in range(self.monitor_number)]
self.thumbnailNumber = wx.ComboBox(self, -1, size=(-1,-1) , choices=self.MonitorList, style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT)
self.Bind(wx.EVT_COMBOBOX, self.onChangeMonitor, self.thumbnailNumber)
self.sourceTXTBOX = wx.TextCtrl (self, -1, "No monitor selected", style=wx.TE_READONLY)
self.sbSizer_1.Add ( self.thumbnailNumber, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
self.sbSizer_1.Add ( self.sourceTXTBOX, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 5 )
#Static box2: mask parameters
sb_2 = wx.StaticBox(self, -1, "Mask Editing")#, size=(250,-1))
sbSizer_2 = wx.StaticBoxSizer (sb_2, wx.VERTICAL)
fgSizer_1 = wx.FlexGridSizer( 0, 2, 0, 0 )
self.btnClear = wx.Button( self, wx.ID_ANY, label="Clear All")
self.Bind(wx.EVT_BUTTON, self.fsPanel.ClearAll, self.btnClear)
self.btnClearLast = wx.Button( self, wx.ID_ANY, label="Clear selected")
self.Bind(wx.EVT_BUTTON, self.fsPanel.ClearLast, self.btnClearLast)
self.btnAutoFill = wx.Button( self, wx.ID_ANY, label="Auto Fill")
self.Bind(wx.EVT_BUTTON, self.fsPanel.AutoMask, self.btnAutoFill)
fgSizer_1.Add (self.btnClear)
fgSizer_1.Add (self.btnClearLast)
fgSizer_1.Add (self.btnAutoFill)
sbSizer_2.Add (fgSizer_1)
#Static box3: mask I/O
sb_3 = wx.StaticBox(self, -1, "Mask File")#, size=(250,-1))
sbSizer_3 = wx.StaticBoxSizer (sb_3, wx.VERTICAL)
self.currentMaskTXT = wx.TextCtrl (self, -1, "No Mask Loaded", style=wx.TE_READONLY)
btnSizer_1 = wx.BoxSizer(wx.HORIZONTAL)
self.btnLoad = wx.Button( self, wx.ID_ANY, label="Load Mask")
self.Bind(wx.EVT_BUTTON, self.onLoadMask, self.btnLoad)
self.btnSave = wx.Button( self, wx.ID_ANY, label="Save Mask")
self.Bind(wx.EVT_BUTTON, self.onSaveMask, self.btnSave)
self.btnSaveApply = wx.Button( self, wx.ID_ANY, label="Save and Apply")
self.Bind(wx.EVT_BUTTON, self.onSaveApply, self.btnSaveApply)
btnSizer_1.Add(self.btnLoad)
btnSizer_1.Add(self.btnSave)
btnSizer_1.Add(self.btnSaveApply)
sbSizer_3.Add ( self.currentMaskTXT, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 5 )
sbSizer_3.Add (btnSizer_1, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
##
#Static box4: help
sb_4 = wx.StaticBox(self, -1, "Help")
sbSizer_4 = wx.StaticBoxSizer (sb_4, wx.VERTICAL)
titleFont = wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD)
instr = [ ('Left mouse button - single click outside ROI', 'Start dragging ROI. ROI will be a perfect rectangle'),
('Left mouse button - single click inside ROI', 'Select ROI. ROI turns red.'),
# ('Left mouse button - double click', 'Select corner of ROI.\nWill close ROI after fourth selection'),
('Left mouse button - double click', 'Add currently selected ROI. ROI turns white.'),
# ('Middle mouse button - single click', 'Add currently selected ROI. ROI turns white.'),
('Right mouse button - click', 'Remove selected currently selected ROI'),
('Auto Fill', 'Will fill 32 ROIS (16x2) to fit under the last two\nselected points. To use select first upper left corner,\n then the lower right corner, then use "Auto Fill".')
]
for title, text in instr:
t = wx.StaticText(self, -1, title); t.SetFont(titleFont)
sbSizer_4.Add( t, 0, wx.ALL, 2 )
sbSizer_4.Add(wx.StaticText(self, -1, text) , 0 , wx.ALL, 2 )
sbSizer_4.Add ( (wx.StaticLine(self)), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
sizer_4.Add(self.sbSizer_1, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 5 )
sizer_4.Add(sbSizer_2, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 5 )
sizer_4.Add(sbSizer_3, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 5 )
sizer_4.Add(sbSizer_4, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 5 )
sizer_3.Add(self.fsPanel, 0, wx.LEFT|wx.TOP, 20 )
sizer_3.Add(sizer_4, 0, wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
sizer_1.Add(sizer_3, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
sizer_1.Add(sizer_2, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
self.SetSizer(sizer_1)
def StopPlaying(self):
"""
"""
if self.fsPanel and self.fsPanel.isPlaying: self.fsPanel.Stop()
def onChangeMonitor(self, event):
"""
FIX THIS
this is a mess
"""
if self.fsPanel.isPlaying: self.fsPanel.Stop()
self.monitor_name = event.GetString()
self.monitor_number = self.MonitorList.index( self.monitor_name )
n_cams = options.GetOption("Webcams")
WebcamsList = [ 'Webcam %s' % (int(w) +1) for w in range( n_cams ) ]
if options.HasMonitor(self.monitor_number):
sourceType, source, track, mask_file, trackType, isSDMonitor = options.GetMonitor(self.monitor_number)
self.fsPanel.setMonitor( source )
self.fsPanel.Play()
if mask_file:
self.fsPanel.mon.loadROIS(mask_file)
self.currentMaskTXT.SetValue(os.path.split(mask_file)[1] or '')
if sourceType == 0:
self.sourceTXTBOX.SetValue( WebcamsList[source] )
else:
self.sourceTXTBOX.SetValue( os.path.split(source)[1] )
else:
sourceType, source, track, mask_file, trackType = [0, '', False, '', 1]
self.sourceTXTBOX.SetValue('No Source for this monitor')
def onSaveMask(self, event):
"""
Save ROIs to File
"""
filename = '%s.msk' % self.monitor_name.replace(' ','_')
wildcard = "pySolo mask file (*.msk)|*.msk"
dlg = wx.FileDialog(
self, message="Save file as ...", defaultDir=os.getcwd(),
defaultFile=filename, wildcard=wildcard, style=wx.SAVE
)
#dlg.SetFilterIndex(2)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.fsPanel.mon.saveROIS(path)
self.currentMaskTXT.SetValue(os.path.split(path)[1])
dlg.Destroy()
return path
def onSaveApply(self, event):
"""
Save ROIs to file and apply to current monitor
"""
path = self.onSaveMask(None)
mn = self.monitor_name.replace(' ','')
options.SetValue(mn, 'maskfile', path)
options.Save()
def onLoadMask(self, event):
"""
Load Mask from file
"""
wildcard = "pySolo mask file (*.msk)|*.msk"
dlg = wx.FileDialog(
self, message="Choose a file",
defaultDir=os.getcwd(),
defaultFile="",
wildcard=wildcard,
style=wx.OPEN | wx.CHANGE_DIR
)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
self.fsPanel.mon.loadROIS(path)
self.currentMaskTXT.SetValue(os.path.split(path)[1])
dlg.Destroy()
def onRefresh(self):
if self.monitor_number != options.GetOption("Monitors"):
self.monitor_number = options.GetOption("Monitors")
self.sbSizer_1.Hide(0)
self.sbSizer_1.Remove(0)
self.MonitorList = ['Monitor %s' % (int(m) + 1) for m in range(self.monitor_number)]
self.thumbnailNumber = wx.ComboBox(self, -1, size=(-1,-1) , choices=self.MonitorList, style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT)
self.sbSizer_1.Insert (1, self.thumbnailNumber, 0, wx.ALIGN_CENTRE|wx.LEFT|wx.RIGHT|wx.TOP, 5 )
self.sbSizer_1.Layout()