Commit 62dfe9b8 authored by Kieran Hymas's avatar Kieran Hymas

Added blurring menu. To do: fix label alignment in blur menu

parent 29ab5e75
......@@ -25,13 +25,16 @@ class Application:
'vMirror' : False, \
'hMirror' : False, \
'Rotate' : 0, \
'Blur' : False, \
'Blur' : BooleanVar(), \
'BlurKernelh' : IntVar(), \
'BlurKernelw' : IntVar(), \
'BlurDeviationX' : IntVar(), \
'BlurDeviationY' : IntVar(), \
'Skew' : False \
}
#Toolbar options
self.toolbarExists = False
self.toolbarPressed = -1
self.icons = [tk.PhotoImage(file="./assets/icons/snapshot.png"), \
tk.PhotoImage(file="./assets/icons/record.png"), \
tk.PhotoImage(file="./assets/icons/rotate.png"), \
......@@ -43,6 +46,11 @@ class Application:
tk.PhotoImage(file="./assets/icons/brush.png"), \
tk.PhotoImage(file="./assets/icons/edge.png") \
]
#Blur options
self.blurOptionsExists = False
#INIT
self.initApp()
self.window.mainloop()
......@@ -53,6 +61,7 @@ class Application:
self.initMenubar()
self.initToolbar()
#Menubar functions
def initMenubar(self):
menubar = Menu(self.window)
self.window.config(menu=menubar)
......@@ -80,12 +89,14 @@ class Application:
helpmenu.add_command(label="About", command=self.onAbout)
menubar.add_cascade(label="Help", menu=helpmenu)
#Toolbar functions
def initToolbar(self):
if self.toolbarExists:
return
self.toolbarExists = True
toolbar = Toplevel(self.window, bd=1, relief=RAISED)
toolbar.title("Pycroscope: Toolbar")
toolbar.geometry("+" + str(self.window.winfo_screenwidth()) + "+" + str(self.window.winfo_screenheight() // 3))
#load icons
......@@ -115,7 +126,7 @@ class Application:
pair4 = Frame(toolbar)
blurButton = Button(pair4, relief=FLAT, image=self.icons[6], command=self.onBlur)
blurButton.pack(side=LEFT, padx=1, pady=1)
colourButton = Button(pair4, relief=FLAT, image=self.icons[7], command=self.onColor)
colourButton = Button(pair4, relief=FLAT, image=self.icons[7], command=self.onColour)
colourButton.pack(side=LEFT, padx=1, pady=1)
pair4.pack(side=TOP)
......@@ -126,17 +137,54 @@ class Application:
edgeButton.pack(side=LEFT, padx=1, pady=1)
pair5.pack(side=TOP)
toolbarsep = Frame(toolbar, height=2, bd=1, relief='sunken')
toolbarsep.pack(fill=X, padx=5, pady=5)
toolbar.protocol("WM_DELETE_WINDOW", lambda arg=toolbar : self.onClosingToolbar(arg))
pair6 = Frame(toolbar)
button1 = Button(pair6, relief=FLAT)
button1.pack(side=LEFT, padx=1, pady=1)
button2 = Button(pair6, relief=FLAT)
button2.pack(side=LEFT, padx=1, pady=1)
pair6.pack(side=TOP)
def onClosingToolbar(self, widget):
self.toolbarExists = False
widget.destroy()
toolbar.protocol("WM_DELETE_WINDOW", lambda arg=toolbar: self.onClosingToolbar(arg))
#Blur options functions
def initBlurOptionsWindow(self):
if self.blurOptionsExists:
return
self.blurOptionsExists = True
blurOptions = Toplevel(self.window, bd=1)
blurcheck = Checkbutton(blurOptions, text="Apply Guassian blur", variable=self.options['Blur'])
blurcheck.pack(side=TOP)
blurOptionsWidget = Frame(blurOptions)
blurOptionsLabels = Frame(blurOptionsWidget)
blurkernelhlabel = Label(blurOptionsLabels, text="Blur kernel height")
blurkernelhlabel.pack(side=TOP)
blurkernelllabel = Label(blurOptionsLabels, text="Blur kernel length")
blurkernelllabel.pack(side=TOP)
blurdeviationXlabel = Label(blurOptionsLabels, text="Standard deviation X-axis")
blurdeviationXlabel.pack(side=TOP)
blurdeviationYlabel = Label(blurOptionsLabels, text="Standard deviation Y-axis")
blurdeviationYlabel.pack(side=TOP)
blurOptionsLabels.pack(side=LEFT)
blurOptionsScales = Frame(blurOptionsWidget)
blurkernelhscale = Scale(blurOptionsScales, from_=0, to=50, orient=HORIZONTAL, resolution=2, variable=self.options['BlurKernelh'])
blurkernelhscale.pack(side=TOP)
blurkernellscale = Scale(blurOptionsScales, from_=0, to=50, orient=HORIZONTAL, resolution=2, variable=self.options['BlurKernelw'])
blurkernellscale.pack(side=TOP)
blurdeviationXscale = Scale(blurOptionsScales, from_=0, to=50, orient=HORIZONTAL, variable=self.options['BlurDeviationX'])
blurdeviationXscale.pack(side=TOP)
blurdeviationYscale = Scale(blurOptionsScales, from_=0, to=50, orient=HORIZONTAL, variable=self.options['BlurDeviationY'])
blurdeviationYscale.pack(side=TOP)
blurOptionsScales.pack(side=LEFT)
blurOptionsWidget.pack(side=TOP)
blurOptions.protocol("WM_DELETE_WINDOW", lambda arg=blurOptions : self.onClosingBlurOptions(arg))
def onClosingBlurOptions(self, widget):
self.blurOptionsExists = False
widget.destroy()
#Menubar options
#File
......@@ -154,47 +202,40 @@ class Application:
#Toolbar functions
def onSnapshot(self):
print("Snapshot!")
self.toolbarPressed = 0
print("Snapshot")
def onRecord(self):
print("Record!")
self.toolbarPressed = 1
print("Record")
def onRotate(self):
self.options['Rotate'] = np.mod(self.options['Rotate'] + 1, 4)
self.toolbarPressed = 2
Print("Rotate")
def onSkew(self):
self.options['Skew'] = not self.options['Skew']
self.toolbarPressed = 3
print("Skew")
def onvMirror(self):
self.options['vMirror'] = not self.options['vMirror']
self.toolbarPressed = 4
print("vMirror")
def onhMirror(self):
self.options['hMirror'] = not self.options['hMirror']
self.toolbarPressed = 5
print("hMirror")
def onBlur(self):
self.options['Blur'] = not self.options['Blur']
self.toolbarPressed = 6
#self.options['Blur'] = not self.options['Blur']
self.initBlurOptionsWindow()
def onColor(self):
def onColour(self):
self.options['BnW'] = not self.options['BnW']
self.toolbarPressed = 7
print("Colour")
def onBrush(self):
self.toolbarPressed = 8
print("Brush")
def onEdge(self):
self.toolbarPressed = 9
#Misc
def onClosingToolbar(self, widget):
self.toolbarExists = False
widget.destroy()
print("Edge")
#Videostream functions
def getPossibleVideoStreams(self):
......
......@@ -25,8 +25,8 @@ class VideoStream:
frame = cv2.flip(frame, 0)
if options['hMirror']:
frame = cv2.flip(frame, 1)
if options['Blur']:
frame = cv2.GaussianBlur(frame, (11, 11), 2.0)
if options['Blur'].get():
frame = cv2.GaussianBlur(frame, (options['BlurKernelh'].get() + 1, options['BlurKernelw'].get() + 1), options['BlurDeviationX'].get(), options['BlurDeviationY'].get())
if options['Skew']:
pass
if ret:
......
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