Skip to content

Commit 5c87174

Browse files
committed
Added additional scripts
1 parent 3b15d25 commit 5c87174

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import mediapipe as mp
2+
import cv2
3+
import numpy as np
4+
import uuid
5+
import os
6+
7+
mp_drawing = mp.solutions.drawing_utils
8+
mp_hands = mp.solutions.hands
9+
10+
cap = cv2.VideoCapture(0)
11+
12+
with mp_hands.Hands(min_detection_confidence=0.8, min_tracking_confidence=0.5) as hands:
13+
while cap.isOpened():
14+
ret, frame = cap.read()
15+
16+
# BGR 2 RGB
17+
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
18+
19+
# Flip on horizontal
20+
image = cv2.flip(image, 1)
21+
22+
# Set flag
23+
image.flags.writeable = False
24+
25+
# Detections
26+
results = hands.process(image)
27+
28+
# Set flag to true
29+
image.flags.writeable = True
30+
31+
# RGB 2 BGR
32+
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
33+
34+
# Detections
35+
print(results)
36+
37+
# Rendering results
38+
if results.multi_hand_landmarks:
39+
for num, hand in enumerate(results.multi_hand_landmarks):
40+
mp_drawing.draw_landmarks(image, hand, mp_hands.HAND_CONNECTIONS,
41+
mp_drawing.DrawingSpec(color=(121, 22, 76), thickness=2, circle_radius=4),
42+
mp_drawing.DrawingSpec(color=(250, 44, 250), thickness=2, circle_radius=2),
43+
)
44+
45+
46+
cv2.imshow('Hand Tracking', image)
47+
48+
if cv2.waitKey(10) & 0xFF == ord('q'):
49+
break
50+
51+
cap.release()
52+
cv2.destroyAllWindows()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
numpy==1.19.5
2+
opencv_python==4.5.2.52
3+
mediapipe==0.8.7.3

0 commit comments

Comments
 (0)