forked from Promobot-MTS/Promobot-MTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraWindow2.py
134 lines (95 loc) · 3.58 KB
/
CameraWindow2.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
128
129
130
131
132
133
from tkinter import *
import time
import alert
import baza.db_fases as db
from PIL import ImageTk, Image
import cv2
import FaceAlgo
import CameraWindow
from win32api import GetSystemMetrics
print("Screen width =", GetSystemMetrics(0))
screen_width = GetSystemMetrics(0)
print("Screen height =", GetSystemMetrics(1))
screen_height = GetSystemMetrics(1)
window_height = 545
window_width = 700
#Capture video frames
bluure=5
mashtab=1
face_cascade = cv2.CascadeClassifier('C:\CV_Start\haarcascades\haarcascade_frontalface_default.xml')
count_frame=0
detect_faces_opencv=False
def show_frame():
#print("получили кадр")
global lmain, cap, var0, mashtab, count_frame, detect_faces_opencv, nameMTS
_, frame = cap.read()
count_frame+=1
frame, face_descriptors = FaceAlgo.find_faces_in_image(frame, bluure, True )
for face_descriptor in face_descriptors:
#отрисовываем и проверяем все найденные лица
ret, dist = FaceAlgo.compare_face(face_descriptor[0])
print(ret, dist)
# if ret:
# if len(ret)>0:
# d = face_descriptor[1]
# cv2.putText(frame, str(str(round(dist,2))+" "+str(ret[2])), (d.left(), d.top()), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255,0), 2)
# print ("Похож на ", ret[2])
# else:
# print("Улыбочку!)")
frame = cv2.resize(frame, None, fx=mashtab, fy=mashtab, interpolation=cv2.INTER_CUBIC)
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
img = ImageTk.PhotoImage(image=img)
# lmain.image = img
lmain.imgtk = img
lmain.configure(image=img)
#lmain.image = img
lmain.after(1, show_frame)
def save_bluur():
global bluure, bluur_entry
bluure=int(bluur_entry.get())
def set_mashtab_30():
global mashtab
mashtab = 0.3
def set_mashtab_50():
global mashtab
mashtab = 0.5
def set_mashtab_70():
global mashtab
mashtab = 0.7
def set_mashtab_100():
global mashtab
mashtab = 1
def WindowsCamera(data, flag_opencv=False):
global lmain, cap, var0, bluur_entry, detect_faces_opencv
detect_faces_opencv =flag_opencv
t_c = Toplevel()
t_c.title(str("Захват изображения"))
x = round((screen_width / 2) - (window_width / 2))
y = round((screen_height / 2) - (window_height / 2))
t_c.geometry('{}x{}+{}+{}'.format(window_width, window_height, x, y))
#t_c.geometry('670x530+200+200') # ширина=500, высота=400, x=300, y=200
#t.minsize(width=400, height=200)
#t.resizable(True, True) # размер окна может быть изменён только по горизонтали
t_c.resizable(False, False) # размер окна может быть изменён только по горизонтали
t_c.lift()
frame1 = Frame(t_c)
frame1.grid(row=0, column=0)
#cap = cv2.VideoCapture(0)
cap = data
_, frame = cap.read()
lmain = Label(frame1)
def cansel():
t_c.destroy()
time.sleep(1)
CameraWindow.WindowsCamera(cap, False)
def takeApicture():
t_c.destroy()
time.sleep(2)
CameraWindow.WindowsCamera(cap, False)
lmain.grid(row=0, column=0, sticky=(N, W, E, S))
ch1 = Button(frame1, text="<< Отменить", width=13, command=cansel)
ch1.grid(row=1, column=0, sticky=(N, W, E, S))
ch2 = Button(frame1, text="Сделать фото", width=20, command = takeApicture)
ch2.grid(row=1, column=0, sticky=(N, W, E, S))
show_frame() # Display 2