|
|
|
@ -3,11 +3,14 @@ from tkinter import *
|
|
|
|
|
from tkinter import ttk
|
|
|
|
|
from PIL import Image, ImageTk
|
|
|
|
|
import numpy as np # 导入 numpy
|
|
|
|
|
import subprocess # 导入 subprocess 模块
|
|
|
|
|
from gesture_recognition import start_recognition, stop_recognition, release_camera, keep_running
|
|
|
|
|
|
|
|
|
|
WINDOW_WIDTH = 800
|
|
|
|
|
WINDOW_HEIGHT = 705
|
|
|
|
|
|
|
|
|
|
main_launched = False # 标志位,记录 main.py 是否已经启动
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
"""显示欢迎屏幕"""
|
|
|
|
@ -91,8 +94,8 @@ def start_thread(root, canvas, status_label):
|
|
|
|
|
status_label.config(text="正在识别...")
|
|
|
|
|
paused = False
|
|
|
|
|
popup_open = False
|
|
|
|
|
threading.Thread(
|
|
|
|
|
target=lambda: start_recognition(callback=lambda data: root.after(0, update_canvas, canvas, data))).start()
|
|
|
|
|
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):
|
|
|
|
@ -109,30 +112,34 @@ def exit_program():
|
|
|
|
|
window.destroy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_canvas(canvas, data):
|
|
|
|
|
def update_canvas(canvas, fingers, img):
|
|
|
|
|
"""更新画布显示图像或处理手指数"""
|
|
|
|
|
if isinstance(data, np.ndarray): # 确保传入的data是图像数据
|
|
|
|
|
img = Image.fromarray(data)
|
|
|
|
|
if isinstance(img, np.ndarray): # 确保传入的img是图像数据
|
|
|
|
|
img = Image.fromarray(img)
|
|
|
|
|
imgtk = ImageTk.PhotoImage(image=img)
|
|
|
|
|
canvas.create_image(0, 0, anchor=NW, image=imgtk)
|
|
|
|
|
canvas.image = imgtk
|
|
|
|
|
canvas.update()
|
|
|
|
|
else:
|
|
|
|
|
handle_finger_detection(data)
|
|
|
|
|
handle_finger_detection(fingers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_finger_detection(finger_count):
|
|
|
|
|
"""处理检测到的手指数"""
|
|
|
|
|
global paused, popup_open
|
|
|
|
|
if not popup_open:
|
|
|
|
|
global paused, popup_open, main_launched
|
|
|
|
|
if finger_count == 10 and not main_launched:
|
|
|
|
|
main_launched = True
|
|
|
|
|
launch_main_script()
|
|
|
|
|
elif not popup_open:
|
|
|
|
|
if finger_count == 5:
|
|
|
|
|
paused = True
|
|
|
|
|
popup_open = True
|
|
|
|
|
show_stop_recognition_window()
|
|
|
|
|
elif finger_count == 0:
|
|
|
|
|
paused = True
|
|
|
|
|
popup_open = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def launch_main_script():
|
|
|
|
|
"""启动 main.py 脚本"""
|
|
|
|
|
subprocess.Popen(['python', 'main.py'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_stop_recognition_window():
|
|
|
|
|
"""显示停止识别确认窗口"""
|
|
|
|
|