-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathface_blur.py
53 lines (49 loc) · 1.81 KB
/
face_blur.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
#!/usr/bin/python3
import cv2
import numpy as np
cam_cap=cv2.VideoCapture(0)
cascade=cv2.CascadeClassifier('face.xml')
while cam_cap.isOpened():
status,frame=cam_cap.read()
#gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
#converting to hsv frame
hsv=cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
lower_green=np.array([0,0,9])
upper_green=np.array([133,250,250])
#creating mask
mask=cv2.inRange(hsv,lower_green,upper_green)
#blurring the frame
blur_frame=cv2.GaussianBlur(frame,(15,15),30)
'''
gray_frame=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
#mask_inv = cv2.bitwise_not(mask)
faces=cascade.detectMultiScale(gray_frame,1.5,5)
#cv2.medianBlur(frame,15,new_img)
#kernal = np.ones((480 ,640), "uint8")
for (x,y,w,h) in faces:
hsv=cv2.cvtColor(frame[y:y+h,x:x+w],cv2.COLOR_BGR2HSV)
lower_green=np.array([0,0,9])
upper_green=np.array([133,250,250])
mask=cv2.inRange(hsv,lower_green,upper_green)
blur_frame=cv2.GaussianBlur(frame[y:y+h,x:x+w],(15,15),30)'''
#ret, mask = cv2.threshold(gray,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
final1=cv2.bitwise_and(blur_frame,frame,mask=mask)
#final2=cv2.bitwise_and(frame,blur_frame,mask=mask_inv)
'''
width, height, channels = frame.shape
center = (int(height/2), int(width/2))
output = cv2.seamlessClone(blur_frame, frame, mask, center, cv2.MIXED_CLONE)
'''
cv2.imshow('live',blur_frame)
cv2.imshow('live2',final1)
#cv2.imshow('live3',final2)
#cv2.imshow('live4',mask_inv)
#cv2.imshow('live5',hsv)
#cv2.imshow('live6',output)
#cv2.imshow('live7',lower_green)
#cv2.imshow('live8',upper_green)
# cv2.imshow('live9',mask)
if cv2.waitKey(2) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
cam_cap.release()