Skip to content
Snippets Groups Projects
Commit bf44004d authored by Vajay Mónika's avatar Vajay Mónika
Browse files

window resize with speed

parent 697448f1
Branches
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ import pyautogui
from collections import Counter
from screeninfo import get_monitors
from parameters import DETECTION_SIDE_MARGIN, DETECTION_BOTTOM_MARGIN, DEFAULT_HAND_SIZE
from parameters import DETECTION_SIDE_MARGIN, DEFAULT_HAND_SIZE, VISUALIZATION_MARGIN
MONITOR = get_monitors()[0]
WIDTH, HEIGHT = MONITOR.width, MONITOR.height
......@@ -27,9 +27,9 @@ class Mouse:
def get_hand_pos(self, hand_pos):
self.hand_pos_x = hand_pos[0]
self.hand_pos_y = hand_pos[1]
#print(f"{self.hand_pos_x}, {self.hand_pos_y}")
#print(f"hand size: {self.hand_size}")
#print(f"hand coord: {self.hand_pos_x}, {self.hand_pos_y} \n")
self.resize_coordinates()
#print(f"{self.hand_pos_x}, {self.hand_pos_y} \n")
def add_prediction(self, prediction):
......@@ -52,7 +52,6 @@ class Mouse:
if self.previous_action != action and self.previous_action == "drag":
pyautogui.mouseUp()
self.drag_start = None
print("drop")
self.mouse_control(action)
self.update_init(action)
......@@ -71,9 +70,11 @@ class Mouse:
elif prediction == "move cursor":
#hand_point = ([int(self.hand_pos_x*WIDTH), int(self.hand_pos_y*HEIGHT)])
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, tween = pyautogui.easeOutQuad)
hand_x = np.clip(int(self.hand_pos_x*WIDTH), VISUALIZATION_MARGIN, WIDTH-VISUALIZATION_MARGIN)
hand_y = np.clip(int(self.hand_pos_y*HEIGHT), VISUALIZATION_MARGIN, HEIGHT-VISUALIZATION_MARGIN)
#print(f"x: {hand_x}, y: {hand_y} \n width: {WIDTH}, height: {HEIGHT}")
#pyautogui.moveTo(hand_x, hand_y, tween = pyautogui.easeOutQuad)
pyautogui.moveTo(hand_x, hand_y)
elif prediction == "stop moving":
pyautogui.move(0, 0) # Stop cursor
......@@ -99,13 +100,13 @@ class Mouse:
self.drag_start = self.stop_pos
pyautogui.mouseDown(*self.drag_start)
elif self.drag_start is None:
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)
hand_x = np.clip(int(self.hand_pos_x*WIDTH), VISUALIZATION_MARGIN, WIDTH-VISUALIZATION_MARGIN)
hand_y = np.clip(int(self.hand_pos_y*HEIGHT), VISUALIZATION_MARGIN, HEIGHT-VISUALIZATION_MARGIN)
self.drag_start = [hand_x, hand_y]
pyautogui.mouseDown(*self.drag_start)
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)
hand_x = np.clip(int(self.hand_pos_x*WIDTH), VISUALIZATION_MARGIN, WIDTH-VISUALIZATION_MARGIN)
hand_y = np.clip(int(self.hand_pos_y*HEIGHT), VISUALIZATION_MARGIN, HEIGHT-VISUALIZATION_MARGIN)
pyautogui.moveTo(hand_x, hand_y)
elif prediction == "drop":
pyautogui.mouseUp()
......@@ -127,9 +128,19 @@ class Mouse:
def resize_coordinates(self):
max_x = 1 - 2 * DETECTION_SIDE_MARGIN
self.hand_pos_x = (self.hand_pos_x-DETECTION_SIDE_MARGIN) / (max_x - DETECTION_SIDE_MARGIN) #* DEFAULT_HAND_SIZE/self.hand_size
self.hand_pos_y = (self.hand_pos_y-DETECTION_SIDE_MARGIN) / (DETECTION_BOTTOM_MARGIN - DETECTION_SIDE_MARGIN) #* DEFAULT_HAND_SIZE/self.hand_size
calculated_bottom_margin = (-0.7)*self.hand_size + 1
#default_bottom_margin = -0.7*DEFAULT_HAND_SIZE + 1
if self.hand_size > DEFAULT_HAND_SIZE: # close
#speed = default_bottom_margin / calculated_bottom_margin
speed = 2*(self.hand_size-DEFAULT_HAND_SIZE)**2 + 1
else: # far away
#speed = calculated_bottom_margin / default_bottom_margin
speed = 7*(self.hand_size-DEFAULT_HAND_SIZE)**2 + 1
self.hand_pos_x = (self.hand_pos_x-DETECTION_SIDE_MARGIN) / (max_x - DETECTION_SIDE_MARGIN) * speed
self.hand_pos_y = (self.hand_pos_y-DETECTION_SIDE_MARGIN) / (calculated_bottom_margin - DETECTION_SIDE_MARGIN) * speed
#print(f"DETECTION_BOTTOM_MARGIN: {calculated_bottom_margin} DEFAULT_BOTTOM_MARGIN: {default_bottom_margin} \n SPEED: {speed} \n")
def get_hand_size(self, middle_tip_coord, palm_coord):
self.hand_size = palm_coord[1] - middle_tip_coord[1]
......
#MODEL NAMES
MOUSE_MODEL_NAME = 'mouse_v2.p'
KEYBOARD_MODEL_NAME = ""
......@@ -10,6 +10,9 @@ CAMERA_MARGIN_BOTTON = 70
# DETECTION WINDOW
DETECTION_SIDE_MARGIN = 0.06
DETECTION_BOTTOM_MARGIN = 0.6
#DETECTION_BOTTOM_MARGIN = 0.6 #not used
DEFAULT_HAND_SIZE = 0.5
#VISUALIZATION WINDOW
VISUALIZATION_MARGIN = 10
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment