informramiz / face-detection-opencv Goto Github PK
View Code? Open in Web Editor NEWFace detection using OpenCV and Python
License: Apache License 2.0
Face detection using OpenCV and Python
License: Apache License 2.0
I have successfully detected faces, save cropped face in a folder. Then view the total count of detected faces on the video using cv2.puttext.
Now I want to show each cropped face on the video just like I am showing the total count.
The code is as follows:
import numpy as np
import cv2
import time
from time import strftime
num = 0
total = 0
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
previous_millis = 0
while 1:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,'Person Count Algorithm',(10,50), font, 1,(255,0,0),2,cv2.LINE_AA)
S1=int(strftime("%S")) #how many frames per second #???
#print "timing"
#print(S1)
millis = int(round(time.time() * 5000)) #it is simply watching the clock in milli second and waiting for 1000 milli seconds to pass #?
#when it does it resets the time and calls your face detection and repeats
interval = 2000
#print(millis) #?
if(int(millis-previous_millis) >= interval):
previous_millis = millis
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
#time.sleep(2)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.putText(img, 'person', (x,y-10), cv2.FONT_HERSHEY_SIMPLEX, 1.5, (255,0,0), 2)
cv2.imwrite('crop_faces/crop'+str(num)+'.jpg',roi_color)
num = num + 1
print ("FOUND", len(faces), 'PERSON')
total += len(faces)
print ('Total Count:', (total))
font = cv2.FONT_HERSHEY_SIMPLEX
img = cv2.circle(img, (470, 63), 63, (255,0,0), 3)
cv2.putText(img, 'Total Count:', (420,40), font, 0.5,(255,0,0),1,cv2.LINE_AA)
cv2.putText(img, str(total), (436,100), font, 2,(255,0,0),2,cv2.LINE_AA)
cv2.imshow('image',img)
k = cv2.waitKey(1) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
Any help is appreciated. Thanks in advance.
How can I test the Accuracy?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.