-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
32 lines (26 loc) · 877 Bytes
/
test.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
import cv2
cap = cv2.VideoCapture(0)
def findFace(img):
faceCascade = cv2.CascadeClassifier("Resources/haarcascade_frontalface_default.xml")
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imgGray, 1.2, 8)
myFaceListC = []
myFaceListArea = []
for (x, y, w, h) in faces:
cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,255), 2)
cx = x + w // 2
cy = y + h // 2
area = w * h
cv2.circle(img, (cx, cy),5,(0,255,0), cv2.FILLED )
myFaceListC.append([cx,cy])
myFaceListArea.append(area)
if len(myFaceListArea) != 0:
i= myFaceListArea.index(max(myFaceListArea))
return img, [myFaceListC[i],myFaceListArea[i]]
else:
return img, [[0,0],0]
while True:
_, img = cap.read()
findFace(img)
cv2.imshow("cam", img)
cv2.waitKey(1)