for id, lm in enumerate(myHand.landmark): h, w, c = image.shape cx, cy = int(lm.x * w), int(lm.y * h) lmList.append([id, cx, cy]) # Assigning variables for Thumb and Index finger position if len(lmList) != 0: x1, y1 = lmList[4][1], lmList[4][2] x2, y2 = lmList[12][1], lmList[12][2] # Marking Thumb and Index finger cv2.circle(image, (x1,y1),15,(255,255,255)) cv2.circle(image, (x2,y2),15,(255,255,255)) cv2.line(image,(x1,y1),(x2,y2),(0,255,0),3) length = math.hypot(x2-x1,y2-y1) if length < 50: cv2.line(image,(x1,y1),(x2,y2),(0,0,255),3) vol = np.interp(length, [50, 220], [minVol, maxVol]) volume.SetMasterVolumeLevel(vol, None) volBar = np.interp(length, [50, 220], [400, 150]) volPer = np.interp(length, [50, 220], [0, 100])