-
Notifications
You must be signed in to change notification settings - Fork 6
/
App.py
105 lines (52 loc) · 2.29 KB
/
App.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
import tkinter
from tkinter import *
import cv2
import PIL.Image, PIL.ImageTk
import time
from Detection import Face_Detect
from Detection import head_pose
from Detection import Multiple_Face
from Detection import win_switch
from Object import Object_Detector
face_cap = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
class App:
def __init__(self, window,video_source=0):
self.window = window
self.video_source = video_source
self.vid = MyVideoCapture(self.video_source)
self.canvas = tkinter.Canvas(window, width = self.vid.width, height = self.vid.height)
self.canvas.place(x=340,y=90)
self.delay = 2
self.update()
def snapshot(self):
ret, frame = self.vid.get_frame()
if ret:
cv2.imwrite( 'frame' + time.strftime("%d-%m-%Y-%H-%M-%S") + ".jpg", cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
def update(self):
ret, frame = self.vid.get_frame()
head_pose.face_dir(frame)
Multiple_Face.face2(frame)
Object_Detector.object(frame)
Face_Detect.face_dec(frame)
win_switch.test()
if ret:
self.photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(frame))
self.canvas.create_image(0, 0, image = self.photo, anchor = tkinter.NW)
self.window.after(self.delay, self.update)
class MyVideoCapture:
def __init__(self, video_source=0):
self.vid = cv2.VideoCapture(video_source)
self.width = self.vid.get(cv2.CAP_PROP_FRAME_WIDTH)
self.height = self.vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
def get_frame(self):
if self.vid.isOpened():
ret, frame = self.vid.read()
if ret:
return (ret, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
else:
return (ret, None)
else:
return (ret, None)
def __del__(self):
if self.vid.isOpened():
self.vid.release()