From 6e5eebef08a168ae695352fd7adb64ee0a321f3e Mon Sep 17 00:00:00 2001 From: V Moni <vajay.monika@hallgato.ppke.hu> Date: Sat, 11 Jan 2025 17:53:06 +0100 Subject: [PATCH] remove left hand actions when it is not detected --- final_project/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/final_project/main.py b/final_project/main.py index c26394c..60513b1 100644 --- a/final_project/main.py +++ b/final_project/main.py @@ -4,6 +4,7 @@ import numpy as np from sklearn.ensemble import RandomForestClassifier from tkinter import Tk, Label from PIL import Image, ImageTk +import pyautogui from mouse_class import Mouse from keyboard_class import Keyboard @@ -96,7 +97,7 @@ def main(): command = pred[0] mouse.add_prediction(command) - if command == "move cursor" or command == "grab": + if command == "move cursor" or command == "drag": mouse.get_hand_size(right_landmark_list[12], right_landmark_list[0]) mouse.get_hand_pos(right_landmark_list[9]) elif command == "change the model": @@ -119,7 +120,7 @@ def main(): cv2.putText( img=frameRGB, - text=f"{pred[0]} pos {right_landmark_list[8][0]:.2f}, {right_landmark_list[8][1]:.2f}, {MOUSE_ACTIVE}", + text=f"{pred[0]}, MOUSE: {MOUSE_ACTIVE}", org=(30, 30), fontFace=cv2.FONT_HERSHEY_DUPLEX, fontScale=1, color=(255, 0, 0), thickness=1 ) @@ -143,11 +144,15 @@ def main(): pred = model_specialkeys.predict(np.asarray(normalised_left_landmark_list).reshape(1, -1)) command = pred[0] cv2.putText( - img=frameRGB, text=pred[0], org=(30, 30), + img=frameRGB, text=pred[0], org=(30, 60), fontFace=cv2.FONT_HERSHEY_DUPLEX, fontScale=1, color=(0, 255, 0), thickness=1 ) specialkeys.add_prediction(command) + else: + pyautogui.keyUp('shift') + pyautogui.keyUp('ctrl') + pyautogui.keyUp('alt') # Convert frame to Tkinter-compatible format and display frameRGB_resized = cv2.resize(frameRGB, (root.winfo_width(), root.winfo_height())) -- GitLab