Face Count Using Python Step By Step

 

Face Count Using Python Step By Step


#1 Installing Open CV


Open cmd and type pip install opencv-python and press Enter
And wait for several minutes to install OpenCV 

#2 Creating a folder and files

First, make a folder and give a name
Then download a file link:- Face
Paste the downloaded file to the folder which you have created earlier




#3 Open the folder on an editor and start coding

for face count

Open the folder on an editor.
I am using Visual Studio Code and create a file Face_Count.py




Then Start Writing the Code
#Note in cap = cv2.VideoCapture (0)
 I am using 0 because
 I am using internal camera
 If you are using external camera 
Then you put 1 #

import cv2
import numpy as np
import dlib


cap = cv2.VideoCapture(0)
 
detector = dlib.get_frontal_face_detector()
 
while True:
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)
 
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = detector(gray)
 
    i = 0

    for face in faces:      
        x, y = face.left(), face.top()
        x1, y1 = face.right(), face.bottom()
        cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2)
 
        i = i+1
       
        cv2.putText(frame, 'face num'+str(i), (x-10, y-10),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)
        print(face, i)
  
    cv2.imshow('frame', frame)
 
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
 
cap.release()
cv2.destroyAllWindows()




























#4 READY TO RUN

RUN THE Face_Count.py file

0 Comments