Coding Notes

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import cv2 and mediapipe as mp

make variables for mp.solution.hands and mp.solution. 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 = cap.read()
flip the image
results = hands.process(image)
hand_landmarks = results.multi_hand_landmarks
drawHandLandmarks(image, hand_landmarks)
countFingers(image,hand_landmarks)
cv2.imshow("Media Controller", image)
key = cv2.waitkey(1)
if key ==32:
break

cv2.destroyAllWindows()

You might also like