diff --git a/control_mouse.py b/control_mouse.py index 5f82bbf20140956a5a484d62e3398e7cd62468ec..3657c8f15d47ef767069259235774b953c27ce3c 100644 --- a/control_mouse.py +++ b/control_mouse.py @@ -81,6 +81,9 @@ class Mouse: # THIS FUNCTION NOT WORKS ON WINDOWS elif prediction == "drag": pyautogui.mouseDown() + hand_x = np.clip(int(self.hand_pos_x*WIDTH), 0, WIDTH-1) + hand_y = np.clip(int(self.hand_pos_y*HEIGHT), 0, HEIGHT-1) + pyautogui.moveTo(hand_x, hand_y) elif prediction == "drop": pyautogui.mouseUp() elif prediction == "multiple item selection grab": @@ -191,9 +194,9 @@ def main(): cv2.putText(img = frameRGB, text = pred[0], org = (30,30), fontFace = cv2.FONT_HERSHEY_DUPLEX, fontScale = 1, color = (255, 0, 0), thickness = 1) - mouse.add_prediction(mouse_command) - if mouse_command == "move cursor": - mouse.get_hand_pos(landmark_list[8]) + mouse.add_prediction(mouse_command) + if mouse_command == "move cursor" or "grab": + mouse.get_hand_pos(landmark_list[8]) # transform back RGB and show frame with annotation frame_annotated = cv2.cvtColor(frameRGB, cv2.COLOR_RGB2BGR) cv2.imshow('Hand tracking', frame_annotated)