-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-forhead-tracker-detection-only.py
39 lines (31 loc) · 1.28 KB
/
0-forhead-tracker-detection-only.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
import cv2
from cvzone.FaceDetectionModule import FaceDetector
import pyfirmata
import numpy as np
cap = cv2.VideoCapture(0)
ws, hs = 1280, 720
cap.set(3, ws)
cap.set(4, hs)
detector = FaceDetector()
while True:
success, img = cap.read()
img, bboxs = detector.findFaces(img, draw=False)
if bboxs:
#get the coordinate
fx, fy = bboxs[0]["center"][0], bboxs[0]["center"][1]
fy = fy - 90
pos = [fx, fy]
cv2.circle(img, (fx, fy), 80, (0, 0, 255), 2)
cv2.putText(img, str(pos), (fx+15, fy-15), cv2.FONT_HERSHEY_PLAIN, 2, (13, 176, 217), 2 )
cv2.line(img, (0, fy), (ws, fy), (0, 0, 0), 2) # x line
cv2.line(img, (fx, hs), (fx, 0), (0, 0, 0), 2) # y line
cv2.circle(img, (fx, fy), 15, (0, 0, 255), cv2.FILLED)
cv2.putText(img, "TARGET LOCKED", (850, 50), cv2.FONT_HERSHEY_PLAIN, 3, (0, 0, 255), 3 )
else:
cv2.putText(img, "NO TARGET", (880, 50), cv2.FONT_HERSHEY_PLAIN, 3, (0, 0, 255), 3)
cv2.circle(img, (640, 360), 80, (0, 0, 255), 2)
cv2.circle(img, (640, 360), 15, (0, 0, 255), cv2.FILLED)
cv2.line(img, (0, 360), (ws, 360), (0, 0, 0), 2) # x line
cv2.line(img, (640, hs), (640, 0), (0, 0, 0), 2) # y line
cv2.imshow("Image", img)
cv2.waitKey(1)