-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.py
29 lines (26 loc) · 1.05 KB
/
new.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
import cv2
import cvzone
cap = cv2.VideoCapture(0)
cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye_tree_eyeglasses.xml')
num=1
while True:
k=cv2.waitKey(100)
if k==ord('s'):
num=num+1
print(num)
if(num<=29):
overlay = cv2.imread(f'static/Glasses/glass3.png', cv2.IMREAD_UNCHANGED)
# overlay = cv2.imread('static/Glasses/glass6.png'.format(num), cv2.IMREAD_UNCHANGED)
_, frame = cap.read()
gray_scale = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = cascade.detectMultiScale(gray_scale)
for (x, y, w, h) in faces:
#cv2.rectangle(frame,(x, y), (x+w, y+h), (0, 255, 0), 2)
overlay_resize = cv2.resize(overlay,(w,int(h*0.8)))
frame = cvzone.overlayPNG(frame, overlay_resize, [x, y])
cv2.imshow('SnapLens', frame)
if cv2.waitKey(10) == ord('q') or num>29:
break
cap.release()
cv2.destroyAllWindows()