Blur Face:
In some videos, you may see that someone's face is blurred for privacy purposes. You can make the same thing in python and this project can create your next-level resume. So let's see how we can build this project in python
Modules:
In this post, we only use one module that is OpenCV(Open source computer version)
Approach:
- First we will use capture the video with the help of OpenCV
cap = cv2.VideoCapture(0)
2. Then we will use a cascade file "haarcascade_frontalface_default.xml" to recognize the faces in the video, you can find it from here
3. For blurring the faces we will use the Gaussian blur algorithm
blur = cv2.GaussianBlur(ROI,(91,91),0)
cap = cv2.VideoCapture(0)
2. Then we will use a cascade file "haarcascade_frontalface_default.xml" to recognize the faces in the video, you can find it from here
blur = cv2.GaussianBlur(ROI,(91,91),0)
Code
import cv2
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:
ROI = img[y:y+h, x:x+w]
blur = cv2.GaussianBlur(ROI,(91,91),0)
img[y:y+h, x:x+w] = blur
if faces == ():
cv2.putText(img,"No face found",(20,50),cv2.FONT_HERSHEY_COMPLEX,1,(0,0,255))
cv2.imshow('Blur Face',img)
if cv2.waitKey(1) & 0xff==ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Output:
Github:
You can also get the code from here
Comments
Post a Comment