forked from ajinkya110001/ERC-HandDetectionAssignment
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
22 lines (17 loc) · 818 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import cv2
import mediapipe as mp
mp_hands = mp.solutions.hands.Hands()
cap = cv2.VideoCapture(0)
while True:
success, frame = cap.read()
imgRGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = mp_hands.process(imgRGB)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
if hand_landmarks.landmark[mp.solutions.hands.HandLandmark.INDEX_FINGER_TIP].x < hand_landmarks.landmark[mp.solutions.hands.HandLandmark.MIDDLE_FINGER_TIP].x:
cv2.putText(frame, "Left Hand", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
else:
cv2.putText(frame, "Right Hand", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.imshow("Image", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break