Skip to content
Snippets Groups Projects
Select Git revision
  • 697448f1c58442fd031197e54e8d2b57cffef444
  • main default protected
2 results

tools.py

Blame
  • tools.py 1.46 KiB
    import os
    import pickle
    from tkinter import Tk, Label
    
    from parameters import (MOUSE_MODEL_NAME, KEYBOARD_MODEL_NAME, 
                            CAMERA_WINDOW_WIDTH, CAMERA_WINDOW_HEIGHT, CAMERA_MARGIN_RIGHT, CAMERA_MARGIN_BOTTON)
    
    def load_model(device):
        current_dir = os.path.dirname(__file__)
        if device == "mouse":
            model_path = os.path.abspath(os.path.join(current_dir, os.pardir, 'trained_models', MOUSE_MODEL_NAME))
        elif device == "keyboard":
            model_path = os.path.abspath(os.path.join(current_dir, os.pardir, 'trained_models', KEYBOARD_MODEL_NAME))
        model_dict = pickle.load(open(model_path, 'rb'))
        model = model_dict['model']
    
        return model
    
    def set_camera_window():
        # set up Tkinter window
        root = Tk()
        root.title("Hand Tracking - Always on Top")
        root.attributes("-topmost", True)
        video_label = Label(root)
        video_label.pack()
    
        # adjust window geometry
        # Get the screen width and height
        screen_width = root.winfo_screenwidth()
        screen_height = root.winfo_screenheight()
        
        # Define window size and position (e.g., 320x240 window at bottom-right corner)
        x_position = screen_width - CAMERA_WINDOW_WIDTH - CAMERA_MARGIN_RIGHT  # 10px margin from the right
        y_position = screen_height - CAMERA_WINDOW_HEIGHT - CAMERA_MARGIN_BOTTON  # 50px margin from the bottom
    
        # Set window geometry
        root.geometry(f"{CAMERA_WINDOW_WIDTH}x{CAMERA_WINDOW_HEIGHT}+{x_position}+{y_position}")
    
        return root, video_label