-
Notifications
You must be signed in to change notification settings - Fork 0
/
FaceRecognition_Arduino.py
65 lines (45 loc) · 1.58 KB
/
FaceRecognition_Arduino.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
63
64
65
import cv2
import sys
#cascPath = sys.argv[1]
cascPath = "C:\Users\Tony\Downloads\opencv\sources\data\haarcascades_cuda\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)
video = cv2.VideoCapture(0)
scale_f = float(sys.argv[1])
while True:
ret, frame = video.read()
#not working
#fps = video.get(cv2.CAP_PROP_FPS)
#print fps
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#scaleFactor = 1.1
faces = faceCascade.detectMultiScale(
gray,
scaleFactor = scale_f,
minNeighbors = 5,
minSize = (30, 30),
flags = cv2.CASCADE_SCALE_IMAGE
)
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
print repr(x) + ',' + repr(y)
#motor functions here, to center the camera for point x,y
#the rectangle vertex is top left of the rectangle
#if: c-x < 0, Mh is right; c-x >= 0, Mh is left; c-y < 0, Mv is down; c - y >= 0, Mv is up
#c = 320, 240; it represents the center of the camera's vision
if 320 - x < 0:
#Motor turns right
elif 320 - x > 0:
#Motor turns left
if 240 - y < 0:
#Motor turns down
elif 240 - y > 0:
#Motor turns up
#only want to detect one face at a time for the camera to track
break
cv2.imshow('Video', frame)
#sometimes works
if cv2.waitKey(1) & 0xFF == ord('x'):
break
print repr(video.get(3)) + ',' + repr(video.get(4))
video.release()
cv2.destroyAllWindows()