File size: 1,140 Bytes
afdbcb1
7acc140
ad5fb46
afdbcb1
7ebb572
86c36ee
7ebb572
 
546f703
afdbcb1
1ff395f
0032752
1ff395f
1e29126
afdbcb1
 
 
 
ad5fb46
caff417
546f703
caff417
d333a65
7410fcb
 
 
ad5fb46
7410fcb
afdbcb1
 
caff417
afdbcb1
 
 
1d9e91e
afdbcb1
 
7410fcb
1d9e91e
ecc43ff
 
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
import cv2
import streamlit as st
import tempfile

try:
    face_cascade = cv2.CascadeClassifier('XML/faces.xml')
except Exception:
    st.write("Error loading cascade classifiers")

def censor_face(filePath):
    
    #output_file = 'Output/censored_' + str(filePath.name) + '.mp4'
    
    video=cv2.VideoCapture(filePath.name)
    success, frame = video.read()
    
    height = frame.shape[0]
    width = frame.shape[1]

    #st.write(height, width)

    #gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    #st.write("Frame: " + str(frame))

    tfile2 = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4')
    #tfile2.write("Censored.mp4")
    
    output=cv2.VideoWriter(tfile2.name, 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)
        #tfile2.write(frame)
        success, frame = video.read()    
    
    output.release()    
    #video.release()
    
    return tfile2