File size: 726 Bytes
afdbcb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import cv2

def censor_face(filePath):
    
    output_file = 'censored_' + filePath
    video=cv2.VideoCapture(filePath)
    success, frame = video.read()
    
    height = frame.shape[0]
    width = frame.shape[1]
        
    face_cascade=cv2.CascadeClassifier('XML\faces.xml')
    output=cv2.VideoWriter('censored_' + filePath, cv2.VideoWriter_fourcc(*'mp4v'), 30, (width, height))
    
    while success:
        faces = face_cascade.detectMultiScale(frame, 1.1, 4)
        for (x,y, w, h) in faces: #multiple faces in a video
            frame[y:y+h, x:x+w] = cv2.blur(frame[y:y+h, x:x+w], (150, 150))
        output.write(frame)
        success, frame = video.read()    
    
    output.release()
    return output_file