Detect multiple faces in live streaming and count them using "Haar Cascade frontalface" algorithm.
Code:-
import cv2
import numpy as np
face_model = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture('http://192.168.1.4:8080/video')
while True:
status, photo = cap.read()
face_cor = face_model.detectMultiScale(photo)
total_faces = len(face_cor)
if total_faces == 0:
pass
else:
for (x1,y1,x2,y2) in face_cor:
cv2.rectangle(photo, (x1,y1), (x1+x2, y1+y2), [255,255,0], 3)
total_faces = '%.3f' % total_faces
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(photo, 'Face :'+total_faces, (1000,20), font, 1, [255,255,0], 2)
cv2.imshow('Detced_Faces', photo)
if cv2.waitKey(2) == 13:
break
cap.release()
cv2.destroyAllWindows()
Output:-
Code:-
import cv2
import numpy as np
face_model = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture('http://192.168.1.4:8080/video')
while True:
status, photo = cap.read()
face_cor = face_model.detectMultiScale(photo)
total_faces = len(face_cor)
if total_faces == 0:
pass
else:
for (x1,y1,x2,y2) in face_cor:
cv2.rectangle(photo, (x1,y1), (x1+x2, y1+y2), [255,255,0], 3)
total_faces = '%.3f' % total_faces
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(photo, 'Face :'+total_faces, (1000,20), font, 1, [255,255,0], 2)
cv2.imshow('Detced_Faces', photo)
if cv2.waitKey(2) == 13:
break
cap.release()
cv2.destroyAllWindows()
Output:-
Comments
Post a Comment
Please share your experience.....