forked from raghu917/infinitehackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChethan's Code
More file actions
46 lines (34 loc) · 1.17 KB
/
Chethan's Code
File metadata and controls
46 lines (34 loc) · 1.17 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
45
46
#OpenCv with mediapipe without output
import cv2
import mediapipe as mp
# Initialize MediaPipe Hands
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(min_detection_confidence=0.7, min_tracking_confidence=0.5)
mp_draw = mp.solutions.drawing_utils
# Capture video input from the laptop camera (default camera)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Error: Could not open camera.")
exit()
while True:
ret, frame = cap.read()
if not ret:
print("Error: Could not read frame.")
break
# Flip the frame horizontally for a mirror effect
frame = cv2.flip(frame, 1)
# Convert the frame to RGB
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Process the frame and detect hands
results = hands.process(rgb_frame)
# Draw hand landmarks
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_draw.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
# Display the result
cv2.imshow('Hand Recognition', frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()