-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkinter.py
52 lines (40 loc) · 1.56 KB
/
tkinter.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
import tkinter as tk
from tkinter import *
from PIL import ImageTk, Image
import cv2
class GUI_Window():
def __init__(self):
self.window=tk.Tk()
self.window.title('OpenCV GUI')
self.canv,self.canv2=self.DeclareCanvas(self.window)
image=cv2.imread('test_image.jpg')
image2=cv2.imread('test_image2.jpg')
img=self.FormatImageCanvas(image)
img2=self.FormatImageCanvas(image2)
self.Canv(img,img2,self.canv,self.canv2)
#Updates Window
self.UpdateGUI()
def DeclareCanvas(self,window):
self.canv = Canvas(window, width=448, height=336, bg='white')
self.canv2 = Canvas(window, width=448, height=336, bg='white')
self.canv.grid(row=1, column=0, columnspan=2)
self.canv2.grid(row=1, column=3, columnspan=4)
return self.canv,self.canv2
def FormatImageCanvas(self,img):
#Note: this line is need down below or else blue and red switch. could be useful
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img,(448,336))
img=Image.fromarray(img)
img=ImageTk.PhotoImage(img)
return 0
def Canv(self,img,img2,canv,canv2):
self.canv.create_image((224,168),image=img)
self.canv2.create_image((224,168),image=img2)
def UpdateGUI(self):
self.window.after(1000, self.UpdateGUI)
return 0
def main():
GUI=GUI_Window()
#GUI.mainloop()
if __name__=="__main__":
main()