0% found this document useful (0 votes)
6 views2 pages

Experiment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Experiment

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment-10

import cv2
print(cv2.__version__)
import mediapipe as mp

# Initialize MediaPipe hands and pose solutions


mp_hands = mp.solutions.hands
mp_pose = mp.solutions.pose
mp_drawing = mp.solutions.drawing_utils

# Initialize video capture


cap = cv2.VideoCapture(0)

with mp_hands.Hands(min_detection_confidence=0.5, min_tracking_confidence=0.5) as


hands, \
mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as
pose:

while cap.isOpened():
ret, frame = cap.read()
if not ret:
break

# Flip the frame for a more intuitive webcam view


frame = cv2.flip(frame, 1)

# Convert the frame to RGB


frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

# Process the hand and pose detections


hand_results = hands.process(frame_rgb)
pose_results = pose.process(frame_rgb)

# Draw hand landmarks


if hand_results.multi_hand_landmarks:
for hand_landmarks in hand_results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
frame, hand_landmarks, mp_hands.HAND_CONNECTIONS,
mp_drawing.DrawingSpec(color=(0, 255, 0), thickness=2,
circle_radius=2),
mp_drawing.DrawingSpec(color=(0, 0, 255), thickness=2,
circle_radius=2))

# Draw pose landmarks


if pose_results.pose_landmarks:
mp_drawing.draw_landmarks(
frame, pose_results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
mp_drawing.DrawingSpec(color=(255, 0, 0), thickness=2,
circle_radius=2),
mp_drawing.DrawingSpec(color=(0, 255, 255), thickness=2,
circle_radius=2))

# Display the frame


cv2.imshow('Hand Gesture and Human Pose Detection', frame)
6
# Break the loop on pressing 'q'
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# Release resources
cap.release()
cv2.destroyAllWindows()

You might also like