Hand Detection with Cv2 and Mediapipe Python.
Автор: Asel Induwara
Загружено: 2024-11-30
Просмотров: 178
Описание:
Subscribe to my channel
Code
import cv2
import mediapipe as mp
Initialize MediaPipe Hands model
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(min_detection_confidence=0.7, min_tracking_confidence=0.5)
mp_drawing = mp.solutions.drawing_utils
Start webcam feed
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
Flip the frame horizontally for a later selfie-view display
frame = cv2.flip(frame, 1)
Convert the BGR image to RGB
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
Process the frame and detect hands
results = hands.process(rgb_frame)
If hands are detected
if results.multi_hand_landmarks:
for landmarks in results.multi_hand_landmarks:
Draw hand landmarks
mp_drawing.draw_landmarks(frame, landmarks, mp_hands.HAND_CONNECTIONS)
Display the frame with hand detection
cv2.imshow("Hand Detection", frame)
Exit on pressing 'q'
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Release the webcam and close windows
cap.release()
cv2.destroyAllWindows()
Повторяем попытку...

Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: