-
Notifications
You must be signed in to change notification settings - Fork 113
/
test.py
59 lines (44 loc) · 1.6 KB
/
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
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
import handy
import cv2
# getting video feed from webcam
cap = cv2.VideoCapture(0)
# capture the hand histogram by placing your hand in the box shown and
# press 'A' to confirm
# source is set to inbuilt webcam by default. Pass source=1 to use an
# external camera.
hist = handy.capture_histogram(source=0)
while True:
ret, frame = cap.read()
if not ret:
break
# to block a faces in the video stream, set block=True.
# if you just want to detect the faces, set block=False
# if you do not want to do anything with faces, remove this line
handy.detect_face(frame, block=True)
# detect the hand
hand = handy.detect_hand(frame, hist)
# to get the outline of the hand
# min area of the hand to be detected = 10000 by default
custom_outline = hand.draw_outline(
min_area=10000, color=(0, 255, 255), thickness=2)
# to get a quick outline of the hand
quick_outline = hand.outline
# draw fingertips on the outline of the hand, with radius 5 and color red,
# filled in.
for fingertip in hand.fingertips:
cv2.circle(quick_outline, fingertip, 5, (0, 0, 255), -1)
# to get the centre of mass of the hand
com = hand.get_center_of_mass()
if com:
cv2.circle(quick_outline, com, 10, (255, 0, 0), -1)
cv2.imshow("Handy", quick_outline)
# display the unprocessed, segmented hand
# cv2.imshow("Handy", hand.masked)
# display the binary version of the hand
# cv2.imshow("Handy", hand.binary)
k = cv2.waitKey(5)
# Press 'q' to exit
if k == ord('q'):
break
cap.release()
cv2.destroyAllWindows()