-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathopencv change images using buttons
73 lines (63 loc) · 1.81 KB
/
opencv change images using buttons
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
import cv2
from tkinter import Label, Tk, Button,ttk
from PIL import ImageTk,Image
import os
win = Tk()
win.geometry("600x600")
filters ="RGB","GRAY","HSV","FHSV","HLS"
com_box = ttk.Combobox(win,values = filters)
com_box.current(0)
com_box.place(x=50,y=500,width = 100)
def change_filter(img):
if com_box.get() =="RGB":
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if com_box.get() =="GRAY":
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
if com_box.get() =="HSV":
img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
if com_box.get() =="FHSV":
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV_FULL)
if com_box.get() =="HLS":
img = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)
return img
path = os.getcwd()
myList = os.listdir(path)
list2 = []
for _, imgs in enumerate(myList):
img = imgs.split(".")
if img[1] =="jpg" or img[1] =="png":
list2.append(imgs)
# print(len(list2))
# print(myList)
def to_display(img, label, x, y, w, h):
image = Image.fromarray(img)
image = image.resize((w, h), Image.ANTIALIAS)
pic = ImageTk.PhotoImage(image)
label.configure(image=pic)
label.image = pic
label.place(x=x, y=y)
def switch(i):
label = Label(win, bg="black")
img = cv2.imread(list2[i])
img = change_filter(img)
to_display(img,label,150,20,300,400)
count = 0
#next img
def counup():
global count
count +=1
if count > len(list2)-1:
count = 0
switch(count)
# previous img
def coundown():
global count
count -=1
if count < 0:
count = len(list2)-1
switch(count)
# win.after(700,coundown)
# coundown()
right = Button(win,text="▶",bg="gray",fg="white",command=counup).place(x=330,y=500,width = 40)
left = Button(win,text="◀",bg="gray",fg="white",command=coundown).place(x=230,y=500,width = 40)
win.mainloop()