DETECT AND BLUR OUR FACE(task 7)
HLO GUYS,
Her we are gonna see how we can detcect human faces and blur it out.
so,lets get into it..........
firstlyy,make sure we have installed haarcascade_forntalface_default.xml or not ?
if not install through this link...
This haarcascade is used to detect the faces in live camera action
Now,Lets get in the code.
step:-1
import os -->used to find out the files in our system.
import cv2 -->it brings our webcam into the live action.
step:-2
Insert the file "haarcascade_frontalface_default.xml" into the code
code:-
os.getcwd()
faces = cv2.cascadeClassifier("haarcascade_frontalface_default.xml")
step:-3
capture the video by using opencv
CODE:-
cap = cv2.VideoCapture(0)
step:4
Read the image using "inread" command
The image which was captured should change into grayscale
command:-
gray = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY)
Now,for detect multiple faces at atime we have to use this command..
faces = face.DetectMultipleScale('gray_color' , Scale_factor ='# ' ,Minneighbors ='# ')
Minneighbors -->means how many faces you want to detect in a single frame when live action going on
CODE FOR THIS STEP:-
while True:
_,img = cam.read()
img = cv2.flip(img,1)
gray =cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face.detectMultiScale(gray, 1.3 , 4)
step:-5
Draw the frame for the image in the video you captured through your webcam
CODE:-
for (x,y,w,h) in faces:
cv2.rectangle(img , (x,y),(x+w,y+h),(0,0,255),5)
step:6
Now,blur the image in the video you captured
cv2.medianBlur(input_image, kernel_size)
Comments
Post a Comment