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...

https://r.search.yahoo.com/_ylt=AwrxyxVe.qFhBGAA2Sq7HAx.;_ylu=Y29sbwNzZzMEcG9zAzEEdnRpZAMEc2VjA3Ny/RV=2/RE=1638034142/RO=10/RU=https%3a%2f%2fgist.github.com%2fLearko%2f8f51e58ac0813cb695f3733926c77f52/RK=2/RS=x8PH0wgrJJGZ8Bgl6YgFHUTaUco-

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)

CODE:-

img[y:y+h, x:x+w] = cv2.medianBlur(img[y:y+h, x:x+w], 35)

step:-7

finally,show the image by using the command "imshow"

and 

cv2.imshow('video_name' , image)

assign waitKey() command --> used to stay on our webcam for some time

cv2.waitKey()


After that destroy all windows but using this command..

cv2.DestroyAllWindows()

CODE:-

cv2.imshow("Webcam",img)
    
    key = cv2.waitKey(30)
    
    if key == 27:
        break

cam.release()
cv2.destroyAllWindows()

TOTAL CODE/INPUT:-

import os
import cv2
import numpy as np

os.getcwd()

face = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
cam = cv2.VideoCapture(0)

while True:
    _,img = cam.read()
    img = cv2.flip(img,1)
    gray =cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face.detectMultiScale(gray, 1.3 , 4)

    for (x,y,w,h) in faces:
        cv2.rectangle(img , (x,y),(x+w,y+h),(0,0,255),5)
        img[y:y+h, x:x+w] = cv2.medianBlur(img[y:y+h, x:x+w], 35)
    
    cv2.imshow("Webcam",img)
    
    key = cv2.waitKey(30)
    
    if key == 27:
        break

cam.release()
cv2.destroyAllWindows() 

OUTPUT:-












Comments

Popular posts from this blog

WHAT IS TECHNOLOGY AND WHY TECHNOLOGY,HOW IT'S EVOLVING in NOW-A-DAYS.

SELF RELIANCE DIGITAL INDIA

LINUX ESPEAK COMMANDS