This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added python code for tracking hand on webcamera videofeed
- Loading branch information
Joakim Eriksson
committed
Jul 1, 2020
1 parent
0cccb81
commit c9f3e33
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import cv2 | ||
from hand_tracker import HandTracker | ||
import numpy as np | ||
|
||
palm_model_path = "./models/palm_detection.tflite" | ||
landmark_model_path = "./models/hand_landmark.tflite" | ||
anchors_path = "./data/anchors.csv" | ||
|
||
cap = cv2.VideoCapture(0) | ||
|
||
detector = HandTracker(palm_model_path, landmark_model_path, anchors_path, | ||
box_shift=0.2, box_enlarge=1.3) | ||
|
||
while True: | ||
ret,frame = cap.read() | ||
image = frame[:,:,::-1] | ||
kp, box = detector(image) | ||
|
||
if kp is None: | ||
continue | ||
|
||
clearpoints = [4,8,12,16,20] | ||
lk = None | ||
p = 0 | ||
|
||
# Draw the hand | ||
for keypoint in kp: | ||
if lk is not None: | ||
cv2.line(frame, (int(keypoint[0]),int(keypoint[1])),(int(lk[0]),int(lk[1])), (255,0,255), 2) | ||
lk = keypoint | ||
cv2.circle(frame, (int(keypoint[0]), int(keypoint[1])), 3, (0,255,255), -1) | ||
if p in clearpoints: | ||
lk = kp[0] | ||
p = p + 1 | ||
|
||
# draw the box | ||
for i in range(0,4): | ||
cv2.line(frame, (int(box[i][0]),int(box[i][1])),(int(box[(i+1)&3][0]),int(box[(i+1)&3][1])), (255,255,255), 2) | ||
|
||
cv2.imshow('frame',frame) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break |