forked from Mrinank-Bhowmick/python-beginner-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
44 lines (39 loc) · 1.25 KB
/
base.py
File metadata and controls
44 lines (39 loc) · 1.25 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
35
36
37
38
39
40
41
42
43
44
import cv2
import mediapipe as mp
import time
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
mp_hands = mp.solutions.hands
pTime = 0
cTime = 0
cap = cv2.VideoCapture(0)
hands = mp_hands.Hands()
while True:
success, image = cap.read()
if not success:
print("Ignoring empty camera frame.")
continue
cTime = time.time()
fps = 1 / (cTime - pTime)
pTime = cTime
image.flags.writeable = False
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = hands.process(image)
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
image,
hand_landmarks,
mp_hands.HAND_CONNECTIONS,
mp_drawing_styles.DrawingSpec(color=(0, 0, 256)),
mp_drawing_styles.DrawingSpec(color=(0, 256, 0)),
)
image = cv2.flip(image, 1)
cv2.putText(
image, str(int(fps)), (500, 400), cv2.FONT_HERSHEY_PLAIN, 3, (120, 52, 40), 3
)
cv2.imshow("Camera Result", image)
# print(fps)
cv2.waitKey(1)