GestureBasedVolumeControl
GestureBasedVolumeControl
GestureBasedVolumeControl
By Swaddhay Paladhi
2023
GestureBasedVolumeControl
#importing all the required libraries
import cv2
import mediapipe as mp
import numpy as np
mpDraw = mp.solutions.drawing_utils
devices = AudioUtilities.GetSpeakers()
volbar=400
volper=0
volMin,volMax = volume.GetVolumeRange()[:2]
while True:
#By accessing the list, we can get the information of each hand's corresponding flag bit
h,w,_ = img.shape
cx,cy = int(lm.x*w),int(lm.y*h)
mpDraw.draw_landmarks(img,handlandmark,mpHands.HAND_CONNECTIONS)
if lmList != []:
#x #y
# from numpy we find our length,by converting hand range in terms of volume range ie b/w -63.5 to 0
vol = np.interp(length,[30,350],[volMin,volMax])
volbar=np.interp(length,[30,350],[400,150])
volper=np.interp(length,[30,350],[0,100])
print(vol,int(length))
volume.SetMasterVolumeLevel(vol, None)
cv2.rectangle(img,(50,int(volbar)),(85,400),(0,0,255),cv2.FILLED)
if cv2.waitKey(1) & 0xff==ord(' '): #By using spacebar delay will stop
break