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
b9a65b39
Commit
b9a65b39
authored
6 months ago
by
Vajay Mónika
Browse files
Options
Downloads
Patches
Plain Diff
resize mouse coordinates
parent
aabf10f0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
final_project/main.py
+12
-4
12 additions, 4 deletions
final_project/main.py
final_project/mouse_class.py
+23
-7
23 additions, 7 deletions
final_project/mouse_class.py
with
35 additions
and
11 deletions
final_project/main.py
+
12
−
4
View file @
b9a65b39
...
@@ -47,8 +47,8 @@ def main():
...
@@ -47,8 +47,8 @@ def main():
screen_height
=
root
.
winfo_screenheight
()
screen_height
=
root
.
winfo_screenheight
()
# Define window size and position (e.g., 320x240 window at bottom-right corner)
# Define window size and position (e.g., 320x240 window at bottom-right corner)
window_width
=
160
window_width
=
160
*
4
window_height
=
120
window_height
=
120
*
4
x_position
=
screen_width
-
window_width
-
10
# 10px margin from the right
x_position
=
screen_width
-
window_width
-
10
# 10px margin from the right
y_position
=
screen_height
-
window_height
-
70
# 50px margin from the bottom
y_position
=
screen_height
-
window_height
-
70
# 50px margin from the bottom
...
@@ -95,13 +95,21 @@ def main():
...
@@ -95,13 +95,21 @@ def main():
# apply model
# apply model
pred
=
model
.
predict
(
np
.
asarray
(
normalised_landmark_list
).
reshape
(
1
,
-
1
))
pred
=
model
.
predict
(
np
.
asarray
(
normalised_landmark_list
).
reshape
(
1
,
-
1
))
mouse_command
=
pred
[
0
]
mouse_command
=
pred
[
0
]
hand_size
=
landmark_list
[
0
][
0
]
-
landmark_list
[
12
][
0
],
landmark_list
[
0
][
1
]
-
landmark_list
[
12
][
1
]
cv2
.
putText
(
cv2
.
putText
(
img
=
frameRGB
,
text
=
pred
[
0
],
org
=
(
30
,
30
),
img
=
frameRGB
,
fontFace
=
cv2
.
FONT_HERSHEY_DUPLEX
,
fontScale
=
1
,
color
=
(
255
,
0
,
0
),
thickness
=
1
text
=
f
"
{
pred
[
0
]
}
pos
{
landmark_list
[
8
][
0
]
:
.
2
f
}
,
{
landmark_list
[
8
][
1
]
:
.
2
f
}
"
,
org
=
(
30
,
30
),
fontFace
=
cv2
.
FONT_HERSHEY_DUPLEX
,
fontScale
=
1
,
color
=
(
255
,
0
,
0
),
thickness
=
1
)
cv2
.
putText
(
img
=
frameRGB
,
text
=
f
"
hand size:
{
hand_size
[
0
]
:
.
2
f
}
,
{
hand_size
[
1
]
:
.
2
f
}
"
,
org
=
(
30
,
60
),
fontFace
=
cv2
.
FONT_HERSHEY_DUPLEX
,
fontScale
=
1
,
color
=
(
0
,
255
,
0
),
thickness
=
1
)
)
mouse
.
add_prediction
(
mouse_command
)
mouse
.
add_prediction
(
mouse_command
)
if
mouse_command
==
"
move cursor
"
or
"
grab
"
:
if
mouse_command
==
"
move cursor
"
or
"
grab
"
:
mouse
.
get_hand_size
(
landmark_list
[
12
],
landmark_list
[
0
])
mouse
.
get_hand_pos
(
landmark_list
[
8
])
mouse
.
get_hand_pos
(
landmark_list
[
8
])
# Convert frame to Tkinter-compatible format and display
# Convert frame to Tkinter-compatible format and display
...
...
This diff is collapsed.
Click to expand it.
final_project/mouse_class.py
+
23
−
7
View file @
b9a65b39
...
@@ -5,6 +5,9 @@ from screeninfo import get_monitors
...
@@ -5,6 +5,9 @@ from screeninfo import get_monitors
MONITOR
=
get_monitors
()[
0
]
MONITOR
=
get_monitors
()[
0
]
WIDTH
,
HEIGHT
=
MONITOR
.
width
,
MONITOR
.
height
WIDTH
,
HEIGHT
=
MONITOR
.
width
,
MONITOR
.
height
SIDE_MARGIN
=
0.06
BOTTOM_MARGIN
=
0.6
DEFAULT_HAND_SIZE
=
0.5
class
Mouse
:
class
Mouse
:
def
__init__
(
self
)
->
None
:
def
__init__
(
self
)
->
None
:
...
@@ -12,24 +15,28 @@ class Mouse:
...
@@ -12,24 +15,28 @@ class Mouse:
self
.
predictions
=
[]
self
.
predictions
=
[]
self
.
previous_action
=
None
self
.
previous_action
=
None
self
.
freeze_action
=
False
self
.
freeze_action
=
False
self
.
stop_pos
=
None
self
.
hand_size
=
None
# parameters to fine-tune
# parameters to fine-tune
self
.
action_length
=
15
self
.
action_length
=
5
#self.move_distance = 10
self
.
scroll_distance
=
50
self
.
scroll_distance
=
50
#self.time_checking = 0.5
self
.
stop_pos
=
None
def
get_hand_pos
(
self
,
hand_pos
):
def
get_hand_pos
(
self
,
hand_pos
):
self
.
hand_pos_x
=
hand_pos
[
0
]
self
.
hand_pos_x
=
hand_pos
[
0
]
self
.
hand_pos_y
=
hand_pos
[
1
]
self
.
hand_pos_y
=
hand_pos
[
1
]
#print(f"{self.hand_pos_x}, {self.hand_pos_y}")
self
.
resize_coordinates
()
#print(f"{self.hand_pos_x}, {self.hand_pos_y} \n")
def
add_prediction
(
self
,
prediction
):
def
add_prediction
(
self
,
prediction
):
self
.
predictions
.
append
(
prediction
)
self
.
predictions
.
append
(
prediction
)
if
len
(
self
.
predictions
)
==
self
.
action_length
:
if
len
(
self
.
predictions
)
==
self
.
action_length
:
self
.
make_action
()
self
.
make_action
()
elif
self
.
previous_action
in
{
"
move cursor
"
,
"
scrolling up
"
,
"
scrolling down
"
,
"
scrolling left
"
,
"
scrolling right
"
}:
elif
self
.
previous_action
in
{
"
move cursor
"
,
"
scrolling up
"
,
"
scrolling down
"
,
"
scrolling left
"
,
"
scrolling right
"
}:
if
len
(
self
.
predictions
)
>
3
:
if
len
(
self
.
predictions
)
>
1
:
safe_action
=
self
.
get_major_element
(
self
.
predictions
[
-
3
:])
safe_action
=
self
.
get_major_element
(
self
.
predictions
[
-
3
:])
if
safe_action
==
self
.
previous_action
:
if
safe_action
==
self
.
previous_action
:
self
.
mouse_control
(
self
.
previous_action
)
self
.
mouse_control
(
self
.
previous_action
)
...
@@ -50,8 +57,6 @@ class Mouse:
...
@@ -50,8 +57,6 @@ class Mouse:
self
.
freeze_action
=
action
in
{
"
left click
"
,
"
right click
"
,
"
double click
"
}
# maybe change to keyboard and drops
self
.
freeze_action
=
action
in
{
"
left click
"
,
"
right click
"
,
"
double click
"
}
# maybe change to keyboard and drops
def
mouse_hand_parameters
(
self
):
pass
def
mouse_control
(
self
,
prediction
):
def
mouse_control
(
self
,
prediction
):
if
prediction
==
"
stop execution
"
or
None
:
if
prediction
==
"
stop execution
"
or
None
:
...
@@ -106,3 +111,14 @@ class Mouse:
...
@@ -106,3 +111,14 @@ class Mouse:
major_element
,
_
=
counts
.
most_common
(
1
)[
0
]
major_element
,
_
=
counts
.
most_common
(
1
)[
0
]
return
major_element
return
major_element
def
resize_coordinates
(
self
):
max_x
=
1
-
2
*
SIDE_MARGIN
self
.
hand_pos_x
=
(
self
.
hand_pos_x
-
SIDE_MARGIN
)
/
(
max_x
-
SIDE_MARGIN
)
#* DEFAULT_HAND_SIZE/self.hand_size
self
.
hand_pos_y
=
(
self
.
hand_pos_y
-
SIDE_MARGIN
)
/
(
BOTTOM_MARGIN
-
SIDE_MARGIN
)
#* DEFAULT_HAND_SIZE/self.hand_size
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.
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