-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_datect.py
48 lines (35 loc) · 1.04 KB
/
face_datect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import cv2
import sys
import time
# Get user supplied values
imagePath = sys.argv[1]
cascPath = "haarcascade_frontalface_default.xml"
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
# flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
print("Found {0} faces!".format(len(faces)))
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
now = time.strftime("%c")
## date and time representation
print "Current date & time " + time.strftime("%c")
## Only date representation
print "Current date " + time.strftime("%x")
## Only time representation
print "Current time " + time.strftime("%X")
## Display current date and time from now variable
print ("Current time %s" % now )
print(len(faces))
cv2.imshow("Faces found", image)
cv2.waitKey(0)