Spaces:
Sleeping
Sleeping
Create Face_Censoring.py
Browse files- Face_Censoring.py +23 -0
Face_Censoring.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
|
3 |
+
def censor_face(filePath):
|
4 |
+
|
5 |
+
output_file = 'censored_' + filePath
|
6 |
+
video=cv2.VideoCapture(filePath)
|
7 |
+
success, frame = video.read()
|
8 |
+
|
9 |
+
height = frame.shape[0]
|
10 |
+
width = frame.shape[1]
|
11 |
+
|
12 |
+
face_cascade=cv2.CascadeClassifier('XML\faces.xml')
|
13 |
+
output=cv2.VideoWriter('censored_' + filePath, cv2.VideoWriter_fourcc(*'mp4v'), 30, (width, height))
|
14 |
+
|
15 |
+
while success:
|
16 |
+
faces = face_cascade.detectMultiScale(frame, 1.1, 4)
|
17 |
+
for (x,y, w, h) in faces: #multiple faces in a video
|
18 |
+
frame[y:y+h, x:x+w] = cv2.blur(frame[y:y+h, x:x+w], (150, 150))
|
19 |
+
output.write(frame)
|
20 |
+
success, frame = video.read()
|
21 |
+
|
22 |
+
output.release()
|
23 |
+
return output_file
|