Hi. I got an project in which I have to detect faces and count how many people pass through the web cam. Please Help. Thank You.
I have this code but it only counts the live faces not the total faces
import dlib
import cv2
import numpy as np
videoCapture = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()
res = 0
while True:
ret, frame = videoCapture.read()
frame = cv2.flip(frame, 1)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(gray)
num = 0
l=0
for face in faces:
l = len(faces)
x,y = face.left(),face.top()
hi,wi = face.right(),face.bottom()
cv2.rectangle(frame,(x,y),(hi,wi),(0,0,255),2)
num = num+1
cv2.putText(frame, 'face'+str(num), (x-12,y-12), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0,255,0),2)
cv2.putText(frame, 'Live Face '+str(l), (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2)
cv2.imshow('frame', frame)
con = cv2.waitKey(1)
if con == ord('q'):
res = l
break
print(“result”,res)
videoCapture.release()
cv2.destroyAllWindows()