-
Notifications
You must be signed in to change notification settings - Fork 0
/
blur_video.py
72 lines (37 loc) · 1.44 KB
/
blur_video.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
import cv2
import time
cap = cv2.VideoCapture('./carrie_lam_2.mp4')
face_cascade = cv2.CascadeClassifier('./haarcascades/haarcascade_frontalface_default.xml')
def detect_face(face_img):
#display_img(img)
#face_img = img.copy()
face_rects = face_cascade.detectMultiScale(face_img)
# for fr in face_rects:
# print(fr)
for (x,y,w,h) in face_rects:
face_img[y:y+h,x:x+w] = cv2.medianBlur(face_img[y:y+h,x:x+w],35)
cv2.rectangle(face_img, (x,y), (x+w,y+h), (255,255,255), 2)
#display_img(face_img[y:y+h,x:x+w])
#display_img(cv2.medianBlur(face_img[y:y+h,x:x+w],15))
# print(f'face_rects: {len(face_rects)}')
return face_img
# FRAMES PER SECOND FOR VIDEO
fps = 50
if cap.isOpened()== False:
print("Error opening the video file. Please double check your file path for typos. Or move the movie file to the same location as this script")
# While the video is opened
while cap.isOpened():
ret, frame = cap.read()
if ret == True:
time.sleep(1/fps*2)
frame = detect_face(frame)
cv2.imshow('frame',frame)
# Press q to quit
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Or automatically break this whole loop if the video is over.
else:
break
cap.release()
# Closes all the frames
cv2.destroyAllWindows()