0% found this document useful (0 votes)
12 views1 page

Coding Notes

The document outlines a Python script using OpenCV and MediaPipe to detect hand landmarks and count fingers in real-time through a webcam. It initializes the hands module, captures video, processes frames to identify hand landmarks, and counts the number of fingers displayed. The script also includes functions to draw the detected landmarks and display the finger count on the screen.

Uploaded by

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

Coding Notes

The document outlines a Python script using OpenCV and MediaPipe to detect hand landmarks and count fingers in real-time through a webcam. It initializes the hands module, captures video, processes frames to identify hand landmarks, and counts the number of fingers displayed. The script also includes functions to draw the detected landmarks and display the finger count on the screen.

Uploaded by

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

import cv2 and mediapipe as mp

make variables for [Link] and [Link]. drawing_utils.


drawing the connecting lines and hands module to define the algorithm to detect the
palm
and later detect the 21 landmarks

set the minimum detection and tracking rate in the variable hands.
hands = mp_hands.Hands()

set the track ids


open the camera under any variable. Video capture

definition for countFingers, store image, hand_landmarks, and set


handNO as 0.

rechecking if we got landmarks or not.


get all landmarks of the First Hand VISIBLE, landmarks =
hand_landmarks[handNo].landmark
count fingers by first creating an empty list

for each and every tipIds of all the 5 fingers, for lm_index in tipIds:
get finger tip and bottom --> y position value
use expression to find out the finger bottom's y position
checking if all the 4 fingers are displayed in front of the camera lm_index !=4:

finnger open and finger close code


followed by increasing the finger count by 1
show text in f array for fingers followed by :{totalFingers}
position and size/font type of the text

def drawHandLandmarks(image,hand_landmarks):
if hand_landmarks:
for landmarks in hand_landmarks:
mp_drawing.draw_landmarks(image, landmarks, mp_hands.HAND_CONNECTIONS)
use a while condition and if true,
success,image = [Link]()
flip the image
results = [Link](image)
hand_landmarks = results.multi_hand_landmarks
drawHandLandmarks(image, hand_landmarks)
countFingers(image,hand_landmarks)
[Link]("Media Controller", image)
key = [Link](1)
if key ==32:
break

[Link]()

You might also like