Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IT Management Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Formanek Balázs István
IT Management Project
Commits
bf44004d
Commit
bf44004d
authored
6 months ago
by
Vajay Mónika
Browse files
Options
Downloads
Patches
Plain Diff
window resize with speed
parent
697448f1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
final_project/mouse_class.py
+25
-14
25 additions, 14 deletions
final_project/mouse_class.py
final_project/parameters.py
+5
-2
5 additions, 2 deletions
final_project/parameters.py
with
30 additions
and
16 deletions
final_project/mouse_class.py
+
25
−
14
View file @
bf44004d
...
...
@@ -3,7 +3,7 @@ import pyautogui
from
collections
import
Counter
from
screeninfo
import
get_monitors
from
parameters
import
DETECTION_SIDE_MARGIN
,
DE
TECTION_BOTTOM_MARGIN
,
DEFAULT_HAND_SIZE
from
parameters
import
DETECTION_SIDE_MARGIN
,
DE
FAULT_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
]
...
...
This diff is collapsed.
Click to expand it.
final_project/parameters.py
+
5
−
2
View file @
bf44004d
#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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment