-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChromatica.py
More file actions
100 lines (79 loc) · 3.12 KB
/
Chromatica.py
File metadata and controls
100 lines (79 loc) · 3.12 KB
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
import numpy as np # for processing tensors
import cv2 # for processing image
from tkinter import *
from PIL import ImageTk, Image
from tkinter import filedialog
# Initiallizing the Camera to start Video Capturing
cap = cv2.VideoCapture(0)
# Placing the upper bound and lower bound of chroma in hsv
lb=np.array([0,0,0]) # lb=np.array([190,190,190])
ub=np.array([100,100,100]) # ub=np.array([255,255,255])
#count=0
#list_of_img = ['img.jpg','img1.jpg','img2.png','img3.jpg','img4.jpg','img5.jpg','space.jpg']
# kernel for performing the mrophological operation on the frames
kernel = np.ones((2,2),np.uint8)
flag = 0
filename = " "
root = Tk()
root.title("Chromatica")
# On exit release camera and destroy window.
def exit_():
cap.release()
root.destroy()
root.protocol("WM_DELETE_WINDOW", exit_)
lmain = Label(root)
lmain.pack(side= "left")
sidebar = PanedWindow(root)
chroma_header = LabelFrame(sidebar,text = "Chroma Settings")
var_red = IntVar()
red_scale = Scale(chroma_header, variable = var_red, to=255, orient = HORIZONTAL, label = "Red")
red_scale.pack(fill = "x", expand=1)
var_green = IntVar()
green_scale = Scale(chroma_header, variable = var_green, to=255, orient = HORIZONTAL, label = "Green")
green_scale.pack(fill = "x", expand=1)
var_blue = IntVar()
blue_scale = Scale(chroma_header, variable = var_blue, to= 255, orient = HORIZONTAL, label = "Blue")
blue_scale.pack(fill = "x", expand = 1)
chroma_header.pack(side = "top",fill= "x", expand= 1)
Input_image = LabelFrame(sidebar,text = "Backgound Image Setting")
path_labe = Label(Input_image, text = "Path")
path_labe.pack(fill="x", expand = 1)
path = Entry(Input_image)
path.pack(fill= "x", expand = 1, side = "left")
def browsefunc():
filename = filedialog.askopenfilenames(filetypes=[("Pictures", "*.png |*.PNG | *.jpg |*.JPG")])
path.insert(0,filename)
browsebutton = Button(Input_image, text="Browse", command=browsefunc)
browsebutton.pack(side= "right")
Input_image.pack(side = "top", fill = "x", expand= 1)
sidebar.pack(side= "top",fill = "both", expand=1)
def show_frame():
# reading the image from the camera instance
ret, frame = cap.read()
# Reducing the noise, doing meadian bluring
frame = cv2.medianBlur(frame,3)
# Converting bgr color fromat to HSV format
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Masking image between upper bounds and lower bounds
closing = cv2.inRange(rgb,lb,ub)
# Appling Morphological operation to reduce noise
closing = cv2.morphologyEx(closing, cv2.MORPH_OPEN, kernel,iterations=1)
# providing final input in canvas by combining frame and image
canvas = frame.copy()
canvas[closing != 0] =[0,0,0]
#print(flag)
if(flag == 1):
img = cv2.imread("{}".format(string_p))
img = cv2.resize(img, (640,480))
img[closing == 0]= [0,0,0]
final = canvas + img
# showing the final frame after combining both frame
else:
final = canvas#+img
img = Image.fromarray(final)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(10, show_frame)
show_frame()
root.mainloop()