|
|
|
@ -3,7 +3,6 @@ from tkinter import *
|
|
|
|
|
from tkinter import ttk
|
|
|
|
|
from PIL import Image, ImageTk
|
|
|
|
|
import numpy as np
|
|
|
|
|
import subprocess
|
|
|
|
|
from gesture_recognition import start_recognition, stop_recognition, release_camera, reset_hand_detection
|
|
|
|
|
|
|
|
|
|
WINDOW_WIDTH = 800
|
|
|
|
@ -13,7 +12,6 @@ status_label = None
|
|
|
|
|
root = None
|
|
|
|
|
popup_open = False
|
|
|
|
|
paused = False
|
|
|
|
|
ten_fingers_detected = False
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
"""显示欢迎屏幕"""
|
|
|
|
@ -87,13 +85,13 @@ def show_main_screen():
|
|
|
|
|
|
|
|
|
|
def start_thread(root, canvas, status_label):
|
|
|
|
|
"""启动识别线程"""
|
|
|
|
|
global paused, popup_open, ten_fingers_detected
|
|
|
|
|
if not paused:
|
|
|
|
|
status_label.config(text="正在识别...")
|
|
|
|
|
paused = False
|
|
|
|
|
popup_open = False
|
|
|
|
|
ten_fingers_detected = False
|
|
|
|
|
threading.Thread(target=lambda: start_recognition(callback=lambda fingers, img: root.after(0, update_canvas, canvas, fingers, img))).start()
|
|
|
|
|
global paused, popup_open
|
|
|
|
|
if paused:
|
|
|
|
|
reset_hand_detection() # 重置手部检测状态
|
|
|
|
|
status_label.config(text="正在识别...")
|
|
|
|
|
paused = False
|
|
|
|
|
popup_open = False
|
|
|
|
|
threading.Thread(target=lambda: start_recognition(callback=lambda fingers, img: root.after(0, update_canvas, canvas, fingers, img))).start()
|
|
|
|
|
|
|
|
|
|
def stop_recognition_with_label(status_label):
|
|
|
|
|
"""停止识别并更新状态标签"""
|
|
|
|
@ -123,19 +121,12 @@ def update_canvas(canvas, fingers, img):
|
|
|
|
|
|
|
|
|
|
def handle_finger_detection(finger_count):
|
|
|
|
|
"""处理检测到的手指数"""
|
|
|
|
|
global paused, popup_open, main_launched, ten_fingers_detected
|
|
|
|
|
if finger_count == 10 and not main_launched:
|
|
|
|
|
main_launched = True
|
|
|
|
|
ten_fingers_detected = True
|
|
|
|
|
launch_main_script()
|
|
|
|
|
elif finger_count == 5 and not ten_fingers_detected and not popup_open:
|
|
|
|
|
paused = True
|
|
|
|
|
popup_open = True
|
|
|
|
|
show_stop_recognition_window()
|
|
|
|
|
|
|
|
|
|
def launch_main_script():
|
|
|
|
|
"""启动 main.py 脚本"""
|
|
|
|
|
subprocess.Popen(['python', 'main.py'])
|
|
|
|
|
global paused, popup_open
|
|
|
|
|
if finger_count == 5:
|
|
|
|
|
if not paused and not popup_open:
|
|
|
|
|
paused = True
|
|
|
|
|
popup_open = True
|
|
|
|
|
show_stop_recognition_window()
|
|
|
|
|
|
|
|
|
|
def show_stop_recognition_window():
|
|
|
|
|
"""显示停止识别确认窗口"""
|
|
|
|
@ -145,7 +136,6 @@ def show_stop_recognition_window():
|
|
|
|
|
paused = False
|
|
|
|
|
popup_open = False
|
|
|
|
|
stop_window.destroy()
|
|
|
|
|
reset_hand_detection()
|
|
|
|
|
start_thread(root, canvas, status_label)
|
|
|
|
|
|
|
|
|
|
def on_stop():
|
|
|
|
|