From 7041b274434ed533a498cd68aacbd162faaa2084 Mon Sep 17 00:00:00 2001 From: V Moni <vajay.monika@hallgato.ppke.hu> Date: Fri, 22 Nov 2024 09:56:39 +0100 Subject: [PATCH] smoother scrolling and moving --- developement.txt | 3 +++ final_project/main.py | 1 + final_project/mouse_class.py | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/developement.txt b/developement.txt index ba24405..5a991ee 100644 --- a/developement.txt +++ b/developement.txt @@ -15,4 +15,7 @@ Megbeszélés 2024. 11. 31: mozdulatok: drag: nyitott tenyér -> drop sima cursor stop if előtte drag + +Móni 2024. 11. 22.: + - egér mozgatás már nem szaggatott \ No newline at end of file diff --git a/final_project/main.py b/final_project/main.py index 3002b94..9be031a 100644 --- a/final_project/main.py +++ b/final_project/main.py @@ -85,6 +85,7 @@ def main(): 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) diff --git a/final_project/mouse_class.py b/final_project/mouse_class.py index 0af223b..fdb9bba 100644 --- a/final_project/mouse_class.py +++ b/final_project/mouse_class.py @@ -14,7 +14,7 @@ class Mouse: self.freeze_action = False # parameters to fine-tune - self.action_length = 5 + self.action_length = 15 #self.move_distance = 10 self.scroll_distance = 50 #self.time_checking = 0.5 @@ -28,6 +28,13 @@ class Mouse: self.predictions.append(prediction) if len(self.predictions) == self.action_length: self.make_action() + elif self.previous_action in {"move cursor", "scrolling up", "scrolling down", "scrolling left", "scrolling right"}: + if len(self.predictions) > 3: + safe_action = self.get_major_element(self.predictions[-3:]) + if safe_action == self.previous_action: + self.mouse_control(self.previous_action) + else: + self.mouse_control(self.previous_action) def make_action(self): action = self.get_major_element(self.predictions) -- GitLab