Skip to content

Commit b274c25

Browse files
committed
fixed args
Signed-off-by: Mpho Mphego <mpho112@gmail.com>
1 parent 99eb33b commit b274c25

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

main.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,20 @@ def arg_parser():
9797
"--mouse-precision",
9898
type=str,
9999
default="low",
100-
help="The precision for mouse movement (how much the mouse moves).",
100+
const="low",
101+
nargs="?",
102+
choices=["high", "low", "medium"],
103+
help="The precision for mouse movement (how much the mouse moves). [Default: low]",
101104
)
102105
parser.add_argument(
103106
"-ms",
104107
"--mouse-speed",
105108
type=str,
106109
default="fast",
107-
help="The speed (how fast it moves) by changing",
110+
const="fast",
111+
nargs="?",
112+
choices=["fast", "slow", "medium"],
113+
help="The speed (how fast it moves) by changing [Default: fast]",
108114
)
109115
parser.add_argument(
110116
"--enable-mouse", action="store_true", help="Enable Mouse Movement",
@@ -113,7 +119,9 @@ def arg_parser():
113119
"--debug", action="store_true", help="Show output on screen [debugging].",
114120
)
115121
parser.add_argument(
116-
"--show-bbox", action="store_true", help="Show bounding box and stats on screen [debugging].",
122+
"--show-bbox",
123+
action="store_true",
124+
help="Show bounding box and stats on screen [debugging].",
117125
)
118126

119127
return parser.parse_args()
@@ -148,7 +156,9 @@ def main(args):
148156

149157
for frame in video_feed.next_frame():
150158

151-
predict_end_time, face_bboxes = face_detection.predict(frame, show_bbox=args.show_bbox)
159+
predict_end_time, face_bboxes = face_detection.predict(
160+
frame, show_bbox=args.show_bbox
161+
)
152162

153163
if face_bboxes:
154164
for face_bbox in face_bboxes:
@@ -163,7 +173,7 @@ def main(args):
163173
(x, y, w, h) = face_bbox
164174
face = frame[y:h, x:w]
165175
(face_height, face_width) = face.shape[:2]
166-
# video_feed.show(frame[y:h, x:w], "face")
176+
# video_feed.show(frame[y:h, x:w], "face")
167177

168178
# ensure the face width and height are sufficiently large
169179
if face_height < 20 or face_width < 20:
@@ -188,9 +198,9 @@ def main(args):
188198
head_pose_estimation.show_text(frame, head_pose_angles)
189199
gaze_estimation.show_text(frame, gaze_vector)
190200

191-
print(f"gaze_vector: {gaze_vector}")
201+
print(f"gaze_vector: x: {gaze_vector['x']:.2f}, y: {gaze_vector['y']:.2f}")
192202
if args.enable_mouse:
193-
mouse_controller.move(gaze_vector['x'], gaze_vector['y'])
203+
mouse_controller.move(gaze_vector["x"], gaze_vector["y"])
194204

195205
if args.debug:
196206
video_feed.show(video_feed.resize(frame))

src/model.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,22 +254,23 @@ def preprocess_output(self, inference_results, image, show_bbox=False):
254254
flattened_predictions = np.vstack(inference_results).ravel()
255255
eyes_coords = flattened_predictions[:4]
256256
h, w = image.shape[:2]
257+
eye_size = 10
257258

258259
left_eye_x_coord = int(eyes_coords[0] * w)
259-
left_eye_xmin = left_eye_x_coord - 10
260-
left_eye_xmax = left_eye_x_coord + 10
260+
left_eye_xmin = left_eye_x_coord - eye_size
261+
left_eye_xmax = left_eye_x_coord + eye_size
261262

262263
left_eye_y_coord = int(eyes_coords[1] * h)
263-
left_eye_ymin = left_eye_y_coord - 10
264-
left_eye_ymax = left_eye_y_coord + 10
264+
left_eye_ymin = left_eye_y_coord - eye_size
265+
left_eye_ymax = left_eye_y_coord + eye_size
265266

266267
right_eye_x_coord = int(eyes_coords[2] * w)
267-
right_eye_xmin = right_eye_x_coord - 10
268-
right_eye_xmax = right_eye_x_coord + 10
268+
right_eye_xmin = right_eye_x_coord - eye_size
269+
right_eye_xmax = right_eye_x_coord + eye_size
269270

270271
right_eye_y_coord = int(eyes_coords[3] * h)
271-
right_eye_ymin = right_eye_y_coord - 10
272-
right_eye_ymax = right_eye_y_coord + 10
272+
right_eye_ymin = right_eye_y_coord - eye_size
273+
right_eye_ymax = right_eye_y_coord + eye_size
273274

274275
eyes_coords = {
275276
"left_eye_point": (left_eye_x_coord, left_eye_y_coord),
@@ -286,7 +287,7 @@ def preprocess_output(self, inference_results, image, show_bbox=False):
286287
return eyes_coords, image
287288

288289
@staticmethod
289-
def draw_output(image, eyes_coords, radius=10, color=(0, 0, 255), thickness=2):
290+
def draw_output(image, eyes_coords, radius=20, color=(0, 0, 255), thickness=2):
290291
"""Draw a circle around ROI"""
291292
for eye, coords in eyes_coords.items():
292293
if "point" in eye:
@@ -445,12 +446,11 @@ def preprocess_output(self, inference_results, image, show_bbox, **kwargs):
445446
def draw_output(coords, image, **kwargs):
446447
left_eye_point = kwargs["eyes_coords"]["left_eye_point"]
447448
right_eye_point = kwargs["eyes_coords"]["right_eye_point"]
448-
print(left_eye_point)
449449
cv2.arrowedLine(
450450
image,
451451
(
452452
left_eye_point[0] + int(coords["x"] * 500),
453-
left_eye_point[1] + int(-coords["y"] * 500),
453+
left_eye_point[1] - int(coords["y"] * 500),
454454
),
455455
(left_eye_point[0], left_eye_point[1]),
456456
color=(0, 0, 255),
@@ -461,7 +461,7 @@ def draw_output(coords, image, **kwargs):
461461
image,
462462
(
463463
right_eye_point[0] + int(coords["x"] * 500),
464-
right_eye_point[1] + int(-coords["y"] * 500),
464+
right_eye_point[1] - int(coords["y"] * 500),
465465
),
466466
(right_eye_point[0], right_eye_point[1]),
467467
color=(0, 0, 255),

src/mouse_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ def move(self, x, y):
2525
try:
2626
start_pos = pyautogui.position()
2727
pyautogui.moveRel(
28-
x * self.precision, -1 * y * self.precision, duration=self.speed
28+
-x * self.precision, y * self.precision, duration=self.speed
2929
)
3030
end_pos = pyautogui.position()
3131
logger.info(f"Mouse -> start_pos: {start_pos}, end_pos: {end_pos}")
3232
except pyautogui.FailSafeException:
3333
logger.exception(f"Position: {x}, {y} are out of the screen")
3434
pyautogui.moveRel(
35-
-x * self.precision, 1 * y * self.precision, duration=self.speed
35+
x * self.precision, -1 * y * self.precision, duration=self.speed
3636
)
3737
def left_click(self):
3838
pass

0 commit comments

Comments
 (0)