diff --git a/start_app.bat b/start_app.bat new file mode 100644 index 0000000..8298918 --- /dev/null +++ b/start_app.bat @@ -0,0 +1,35 @@ +@echo off +chcp 65001 >nul +:: 简单启动脚本 - 激活虚拟环境并运行app.py (Windows版本) + +echo 启动YOLO应用... + +:: 检查虚拟环境是否存在 +if not exist "venv" ( + echo ❌ 错误: 虚拟环境不存在! + echo 请先运行 run_app.bat 来创建环境和安装依赖 + pause + exit /b 1 +) + +:: 激活虚拟环境 +echo 激活虚拟环境... +call venv\Scripts\activate.bat + +:: 检查测试视频文件是否存在 +if not exist "res\test.mp4" ( + echo ❌ 错误: res\test.mp4 文件不存在! + echo 请在 res\ 目录中放置名为 test.mp4 的视频文件 + pause + exit /b 1 +) + +echo ✅ 找到测试视频文件: res\test.mp4 + +:: 运行应用 +echo 运行应用... +cd src +python app.py + +echo ✅ 应用运行完成! +pause \ No newline at end of file diff --git a/start_app.py b/start_app.py new file mode 100755 index 0000000..7aa2761 --- /dev/null +++ b/start_app.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +import sys +import subprocess + +def run_command(command, shell=False): + """运行命令并返回结果""" + try: + result = subprocess.run(command, shell=shell, check=True, + capture_output=True, text=True) + return result.returncode, result.stdout, result.stderr + except subprocess.CalledProcessError as e: + return e.returncode, e.stdout, e.stderr + +def main(): + print("启动YOLO应用...") + + # 检查虚拟环境是否存在 + if not os.path.exists("venv"): + print("❌ 错误: 虚拟环境不存在!") + print("请先运行 python3 setup_and_run.py 来创建环境和安装依赖") + sys.exit(1) + + # 确定虚拟环境中的Python解释器路径 + if os.name == 'nt': # Windows + venv_python = os.path.join("venv", "Scripts", "python.exe") + else: # macOS/Linux + venv_python = os.path.join("venv", "bin", "python") + + # 检查虚拟环境的Python是否存在 + if not os.path.exists(venv_python): + print("❌ 错误: 虚拟环境损坏!") + print("请重新创建虚拟环境") + sys.exit(1) + + # 检查测试视频文件是否存在 + if not os.path.exists("res/test.mp4"): + print("❌ 错误: res/test.mp4 文件不存在!") + print("请在 res/ 目录中放置名为 test.mp4 的视频文件") + sys.exit(1) + + print("✅ 找到测试视频文件: res/test.mp4") + + # 运行应用 + print("运行应用...") + os.chdir("src") + returncode, stdout, stderr = run_command([os.path.join("..", venv_python), "app.py"]) + + if returncode == 0: + print("✅ 应用运行完成!") + else: + print(f"❌ 应用运行失败: {stderr}") + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/start_app.sh b/start_app.sh new file mode 100755 index 0000000..2495956 --- /dev/null +++ b/start_app.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# 简单启动脚本 - 激活虚拟环境并运行app.py + +echo "启动YOLO应用..." + +# 检查虚拟环境是否存在 +if [ ! -d "venv" ]; then + echo "❌ 错误: 虚拟环境不存在!" + echo "请先运行 ./run_app.sh 来创建环境和安装依赖" + exit 1 +fi + +# 激活虚拟环境 +echo "激活虚拟环境..." +source venv/bin/activate + +# 检查测试视频文件是否存在 +if [ ! -f "res/test.mp4" ]; then + echo "❌ 错误: res/test.mp4 文件不存在!" + echo "请在 res/ 目录中放置名为 test.mp4 的视频文件" + exit 1 +fi + +echo "✅ 找到测试视频文件: res/test.mp4" + +# 运行应用 +echo "运行应用..." +cd src +python app.py + +echo "✅ 应用运行完成!" \ No newline at end of file