0% found this document useful (0 votes)
64 views3 pages

Hand Gesture Video Controller Code

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)
64 views3 pages

Hand Gesture Video Controller Code

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 the necessary files

controller inside keyboard


[Link] inside mp_hands and [Link] inside
mp_drawing
mp_hands.Hands inside hands with minimum detection confidence as 0.8 and
tracking as 0.5
tip ids
state = None
width = int([Link](cv2.CAP_PROP_FRAME_WIDTH))
height = int([Link](cv2.CAP_PROP_FRAME_WIDTH))
def countFingers(image, hand_landmarks, handNO = 0):
global state
get all landmarks of the First Hand VISIBLE
if hand_landmarks:
landmarks = hand_landmarks[handNO].landmark
make an empy list for variable fingers
for lm_index in tipIds:
#Get finger tip and bottom Y position value
finger_tip_y = landmarks[lm_index].y
finger_bottom_y = landmarks[lm_index-2].y
#check if any finger is open or closed
if lm_index !=4:
[Link](1)
if finger_tip_y > fniger_bottom_y:
[Link](0)
increase total finger count by 1
totalFingers = [Link](1)
#Play or pause a video
if totalFingers ==4:
state = "play"
if totalFingers ==0 and state =="play":
state = "pause"
[Link]([Link])
#Move video forward and backwards
finger_tip_x = (landmarks[8].x)*width
if finger_tip_x < width -400:
print("play backward")
[Link]([Link])
if finger_tip_x > width -60:
print("Play forward")
[Link]([Link])
#define a function to
def drawHandLandmarks(image, hand_landmarks):
draw connection between landmarks points
if hand_landmarks:
for landmarks in hand_landmarks:
mp_drawing.draw_landmarks(image, landmarks, mp_hands.HAND_CONNECTIONS)
while True:
success, image = [Link]()
image = [Link](image,1)
#Detect the Hand Landmarks
results = [Link](image)
#Get the landmark position from the processed result
hand_landmarks = results.multi_hand_landmarks
#Draw landmarks
drawHandLandmarks(image, hand_landmarks)
#Get hand fingers position
countFingers(image,hand_landmarks)
[Link]("Media Controller",image)
#Quit the window on pressing Spacebar key
key = [Link](1)
if key ==27:
break
[Link]()

first part of the code practice


import cv2
import mediapipe as mp
from [Link] import Key, Controller

keyboard = Controller()
cap = [Link](0)
mp_hands = [Link]
mp_drawing = [Link].drawing_utils
hands = mp_hands.Hands(min_detection_confidence = 0.8, min_tracking_confidence =
0.5)
tipIds = [4,8,12,16,20]
state = None
width = int([Link](cv2.CAP_PROP_FRAME_WIDTH))
height = int([Link](cv2.CAP_PROP_FRAME_WIDTH))

to remember -
import the necessary libraries that are cv2, mediapide and key, controller
from [Link]
store controller in keyboard vraiable ()
open camera - cap = [Link](0)
store [Link] in mp_hands variable and [Link].drawing_utils
in mp_drawing
hands = mp_hands.Hands(min_detection_confidence = 0.8 and min_tracking_confidence
as 0.5.
tipIds = [4,8,12,16,20]
state = None
width = int([Link](cv2.CAP_PROP_FRAME_WIDTH))
height = int([Link](cv2.CAP_PROP_FRAME_WIDTH))

import cv2
import mediapipe as mp
from [Link] import Key, Controller
keyboard = Controller()
cap = [Link](0)
mp_hands = [Link]
mp_drawing = [Link].drawing_utils
hands = mp_hands.Hands(min_detection_confidence = 0.8, min_tracking_confidence =
0.5)
tipIds = [4,8,12,16,20]
state = None
width = int([Link](cv2.CAP_PROP_FRAME_WIDTH))
height = int([Link](cv2.CAP_PROP_FRAME_WIDTH))

import cv2
import mediapipe as mp
from [Link] import Keyboard, Controller
keyboard = Controller()
cap = [Link](0)
mp_hands = [Link]
mp_drawing = [Link].drawing_utils
hands = mp_hands.Hands(min_detection_confidence = 0.8, min_tracking_confidence =
0.5)
tipIds[4,8,12,16,20]
state = None
width = int([Link](cv2.CAP_PROP_FRAME_WIDTH))
height = int([Link](cv2.CAP_PROP_FRAME_WIDTH))

icgccpfw
width = int([Link](cv2.CAP_PROP_FRAME_WIDTH))

import cv2
import mediapipe as mp
from [Link] import Keyboard, Controller

You might also like