-
Notifications
You must be signed in to change notification settings - Fork 0
/
blurFaces.py
50 lines (35 loc) · 1.26 KB
/
blurFaces.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
import cv2
cap = cv2.VideoCapture(0)
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
'''
# Create trackbar
cv2.namedWindow("trackbar")
def nothing(x):
pass
cv2.createTrackbar("kernel", "trackbar", 1, 50, nothing)
cv2.createTrackbar("sigma", "trackbar", 1, 50, nothing)
'''
while True:
ret,frame = cap.read()
frame = cv2.flip(frame,1)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray,1.1,3)
for x,y,w,h in faces:
'''
# To draw the boundary for face
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),3)
# Get kernel and sigma values from trackbar to blur faces
k = cv2.getTrackbarPos("kernel", "trackbar")
sig = cv2.getTrackbarPos("sigma", "trackbar")
'''
k = 30
sig = 20
# threshold to blur the whole face
th1,th2 = 40,10
face = frame[y-th1:y+h,x-th2:x+h+th2]
frame[y-th1:y+h,x-th2:x+h+th2] = cv2.GaussianBlur(face, (2*k+1,2*k+1), sig)
cv2.imshow("Video",frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()