-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaceDetectionFromScreenshot.py
62 lines (55 loc) · 1.88 KB
/
faceDetectionFromScreenshot.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import glob
import os
import cv2
import numpy as np
#detects face from latest snap in the directory
files_path = os.path.join('F:\yolo\smart-survelliance\screenshots', '*.png')
files = sorted(
glob.iglob(files_path), key=os.path.getctime, reverse=True)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
for i in files:
#print(i)
j = 1
img = cv2.imread(str(i))
grayImg = cv2.cvtColor(img, 0)
faces = face_cascade.detectMultiScale(grayImg, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,0), 2)
filename = str(j) + 'Face.png'
#path = 'F:\yolo\smart-survelliance\face-detected'
cv2.imwrite(i, img)
#print(i)
#cv2.imwrite(filename, img)
j += 1
"""
i = 1
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread(str(files[0]))
grayImg = cv2.cvtColor(img, 0)
faces = face_cascade.detectMultiScale(grayImg, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,0), 2)
filename = str(i) + 'Face.png'
cv2.imwrite(filename, img)
i += 1
if cv2.waitKey(1) & 0xff == ord('q'):
cv2.destroyAllWindows()
"""
"""
#detects face from all snaps in the dir
for i in os.listdir('F:\yolo\smart-survelliance\screenshots'):
j = 1
print(i)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
img = cv2.imread(i)
grayImg = cv2.cvtColor(img, 0)
faces = face_cascade.detectMultiScale(grayImg, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,0), 2)
filename = str(j) + 'Face.png'
path = 'F:\yolo\smart-survelliance\face-detected'
cv2.imwrite(os.path.join(path, filename), img)
j += 1
if cv2.waitKey(1) & 0xff == ord('q'):
cv2.destroyAllWindows()
"""