-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.py
127 lines (100 loc) · 4.13 KB
/
Code.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
import tkinter as tk
from tkinter import filedialog, font
from tkinter.constants import CENTER
import cv2 as cv
from PIL import Image, ImageTk
def open_a_file():
video_formats = ".mp4 .mkv .mov" # we can add more video formats here
global filename
filename = tk.filedialog.askopenfilename(initialdir="/",title="Select File",
filetypes= [("Video", video_formats)])
labelfont = tk.font.Font(family='Helvetica', size=12, weight='bold')
label = tk.Label(text="Location : "+filename, fg=my_foreground_colour, bg=my_background_colour,
font=labelfont, wraplength=400, justify="left")
label.place(relx=0.5,rely=0.15,anchor=CENTER)
def process():
if(filename!=None):
print("Filename : ",filename)
capture = cv.VideoCapture(filename)
haar_cascase = cv.CascadeClassifier ('haar_face.xml')
while True :
isTrue,frame = capture.read()
if(isTrue==False):
break
gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
faces_rect = haar_cascase.detectMultiScale(gray,1.1,3)
for (x,y,w,h) in faces_rect:
cv.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),thickness=2)
cv.imshow('Detected faces in Video',frame)
if cv.waitKey(1) & 0xFF==ord('d'):
break
if cv.getWindowProperty('Detected faces in Video', cv.WND_PROP_VISIBLE) <1:
break
capture.release()
cv.destroyAllWindows()
def process_webcam():
capture = cv.VideoCapture(0)
haar_cascase = cv.CascadeClassifier ('haar_face.xml')
while True:
isTrue,frame = capture.read()
frame = cv.flip(frame,1)
gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
faces_rect = haar_cascase.detectMultiScale(gray,1.1,3)
for (x,y,w,h) in faces_rect:
cv.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),thickness=2)
cv.imshow('Detected faces in Video',frame)
if cv.waitKey(1) & 0xFF==ord('d'):
break
if cv.getWindowProperty('Detected faces in Video', cv.WND_PROP_VISIBLE) <1:
break
capture.release()
cv.destroyAllWindows()
filename = None
#Initialising Main Window of the application
window = tk.Tk()
window.title("Human Detecting System")
window.geometry("800x800")
window.resizable(False,False)
window.configure(bg="#5cd3ba")
#Initialising font & colours for buttons
buttonFont = font.Font(family='Helvetica', size=16, weight='bold')
my_foreground_colour = "white"
#my_background_colour = "#ff530a"
my_background_colour = "#FF6347"
#Initialising open file button
img = Image.open('icons/openfile.jpg')
img = img.resize((50,50), Image.ANTIALIAS)
open_file_icon = ImageTk.PhotoImage(img)
openFile = tk.Button(window,text="Open File",
padx=12,pady=5,
fg=my_foreground_colour,
bg=my_background_colour,
image = open_file_icon,compound = tk.LEFT,
font=buttonFont,
command=open_a_file)
openFile.place(relx=0.5, rely=0.3, anchor=CENTER)
#Initialising process the file button
img = Image.open('icons/processing.jpg')
img = img.resize((50,50), Image.ANTIALIAS)
processing_icon = ImageTk.PhotoImage(img)
process = tk.Button(window,text="Process",
padx=12,pady=5,
fg=my_foreground_colour,
bg=my_background_colour,
image = processing_icon,compound = tk.LEFT,
font=buttonFont,
command=process)
process.place(relx=0.5, rely=0.5, anchor=CENTER)
#Initialising openwebcam button
img = Image.open('icons/webcam.png')
img = img.resize((50,50), Image.ANTIALIAS)
webcam_icon = ImageTk.PhotoImage(img)
process = tk.Button(window,text="Webcam",
padx=12,pady=5,
fg=my_foreground_colour,
bg=my_background_colour,
image = webcam_icon,compound = tk.LEFT,
font=buttonFont,
command=process_webcam)
process.place(relx=0.5, rely=0.7, anchor=CENTER)
window.mainloop()