Python และ MediaPipe ร่วมกับ OpenCV ทำโปรแกรมนับนิ้ว "Finger Counting"
Summary
TLDRThis video demonstrates how to create a finger-counting application using MediaPipe and OpenCV. It begins by importing the necessary libraries and setting up the MediaPipe hand tracking model. The process includes capturing video from a webcam, detecting hand landmarks, and counting the fingers based on specific landmark positions. The script utilizes OpenCV to display the video feed with annotated hand landmarks and the current finger count. The real-time finger count updates on the screen as the user moves their hands. This tutorial provides a step-by-step guide for building an interactive finger-counting app.
Takeaways
- 😀 MediaPipe and OpenCV are used to detect and count fingers in a real-time video stream.
- 😀 The script uses the `cv2.VideoCapture()` function to capture video from the webcam.
- 😀 MediaPipe's hand detection model (`Hands`) is used to identify hands in the video frames.
- 😀 Hand landmarks are detected and processed to identify finger positions for counting.
- 😀 The script checks the relative positions of specific landmarks (e.g., thumb, index) to count fingers.
- 😀 The finger count is displayed on the video feed using `cv2.putText()` to show the number of fingers.
- 😀 It uses `Hands.process(image)` to detect and process hand landmarks in each frame.
- 😀 The finger count is updated dynamically based on the hand landmarks' positions in the video.
- 😀 MediaPipe provides a connection between the landmarks for drawing lines that represent the hand.
- 😀 The application is designed to run in a loop, updating the finger count as long as the webcam feed is active.
Q & A
What is the purpose of the script provided?
-The script demonstrates how to use MediaPipe and OpenCV to detect hand landmarks and count the number of fingers visible in a webcam feed.
Which libraries are imported in the script, and what are their roles?
-The script imports OpenCV (`cv2`) for video capture and image processing, and MediaPipe (`mp`) for hand landmark detection and drawing.
How does the script process the webcam feed?
-The webcam feed is captured using OpenCV's `VideoCapture()`. Each frame is converted to RGB format before being processed by MediaPipe's hand detection model to detect landmarks and count fingers.
What is the role of `hands = mp_hands.Hands(min_detection_confidence=0.5, min_tracking_confidence=0.5)` in the script?
-This line initializes the MediaPipe hand detection model, setting the minimum confidence thresholds for detecting and tracking hands in the video feed.
How does the script determine whether a finger is extended or not?
-The script checks if the tip of each finger (e.g., index 4, 8, 12, 16, and 20) is positioned higher (has a smaller `y` value) than the previous joint (two landmarks before). If so, the finger is considered extended.
Why is the frame converted to RGB using `cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)`?
-MediaPipe processes images in RGB format, so the frame from the webcam (which is in BGR format) must be converted to RGB before being passed to the hand detection model.
What happens if multiple hands are detected in the frame?
-The script processes each hand detected individually, counting the number of extended fingers for each hand and drawing the landmarks on the frame.
How does the script display the finger count on the frame?
-The script uses OpenCV's `cv2.putText()` function to overlay the finger count on the video feed at the specified position (50, 450) on the frame.
How does the loop handle stopping the video capture?
-The loop continues capturing frames until the user presses the 'q' key. When 'q' is pressed, the loop exits, and the webcam is released with `cap.release()`.
What is the purpose of `mp_drawing.draw_landmarks()` in the script?
-This function draws the detected hand landmarks on the video frame, helping visualize the points used to count fingers and detect hand gestures.
Outlines

Этот раздел доступен только подписчикам платных тарифов. Пожалуйста, перейдите на платный тариф для доступа.
Перейти на платный тарифMindmap

Этот раздел доступен только подписчикам платных тарифов. Пожалуйста, перейдите на платный тариф для доступа.
Перейти на платный тарифKeywords

Этот раздел доступен только подписчикам платных тарифов. Пожалуйста, перейдите на платный тариф для доступа.
Перейти на платный тарифHighlights

Этот раздел доступен только подписчикам платных тарифов. Пожалуйста, перейдите на платный тариф для доступа.
Перейти на платный тарифTranscripts

Этот раздел доступен только подписчикам платных тарифов. Пожалуйста, перейдите на платный тариф для доступа.
Перейти на платный тарифПосмотреть больше похожих видео

25 - Reading Images, Splitting Channels, Resizing using openCV in Python

OpenCV Python Fourier Transform

Capillary Puncture | Finger stick for Glucose Testing | Medical Assistant

Cara Membuat Media Pembelajaran Penjumlahan dan pengurangan Siswa SD || Media Pembelajaran Siswa

HOW TO ANIMATE ON YOUR PHONE FOR BEGINNERS

Most Easy Way To Object Detection & Object Counting In Real Time | computer vision | python opencv
5.0 / 5 (0 votes)