-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandDetector.py
More file actions
34 lines (23 loc) · 1.13 KB
/
handDetector.py
File metadata and controls
34 lines (23 loc) · 1.13 KB
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
import mediapipe as mp
import cv2
mpHands = mp.solutions.hands
mpDraw = mp.solutions.drawing_utils
class HandDetector:
def __init__(self,max_num_hands =2,min_detection_confidence=0.5, min_tracking_confidence=0.5):
self.hands = mpHands.Hands(max_num_hands=max_num_hands,
min_detection_confidence=min_detection_confidence,
min_tracking_confidence=min_tracking_confidence)
def findLandmarks(self, image, handnumber=0, draw=False):
originalImage = image
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = self.hands.process(image)
landMarkList = []
if results.multi_hand_landmarks:
hand = results.multi_hand_landmarks[handnumber]
for id, landmark in enumerate(hand.landmark):
imgH, imgW, imgC = originalImage.shape
xPos, yPos = int(landmark.x * imgW), int(landmark.y * imgH)
landMarkList.append([id, xPos ,yPos])
if draw:
mpDraw.draw_landmarks(originalImage, hand, mpHands.HAND_CONNECTIONS)
return landMarkList