-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaceblur.py
43 lines (28 loc) · 885 Bytes
/
faceblur.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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import cv2
# In[2]:
cap = cv2.VideoCapture(0)
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
while True:
success,img = cap.read()
faces = faceCascade.detectMultiScale(img,1.2,4)
for (x, y, w, h) in faces:
# To make a face blurred
ROI = img[y:y+h, x:x+w]
blur = cv2.GaussianBlur(ROI, (91,91),0)
# Insert ROI back into image
img[y:y+h, x:x+w] = blur
# To make a bounding box #*(Not Necessary)
# cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),4)
if faces==():
cv2.putText(img,'No Face Found!',(20,50),cv2.FONT_HERSHEY_COMPLEX,1,(0,0,255))
cv2.imshow('Face Blur',img)
if cv2.waitKey(1) & 0xff==ord('q'):
break
# Turn camera off
cap.release()
# Close camera window
cv2.destroyAllWindows()
# In[ ]: