checkhand/start_service.bat
2025-08-11 12:24:21 +08:00

181 lines
4.3 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
chcp 65001 > nul
setlocal enabledelayedexpansion
:: 手部检测Web服务启动脚本 (Windows版本)
:: 包含虚拟环境激活和服务启动
:: 设置脚本目录
cd /d "%~dp0"
:: 颜色定义 (Windows CMD不支持颜色使用echo代替)
echo ================================================
echo 🤖 手部检测Web服务启动器 (Windows)
echo ================================================
echo.
:: 检查Python是否存在
python --version >nul 2>&1
if %errorlevel% neq 0 (
echo [ERROR] Python 未找到请先安装Python
pause
exit /b 1
)
for /f "tokens=*" %%i in ('python --version 2^>^&1') do set PYTHON_VERSION=%%i
echo [INFO] Python版本: %PYTHON_VERSION%
:: 检查虚拟环境是否存在
if not exist "venv" (
echo [WARNING] 虚拟环境不存在,正在创建...
python -m venv venv
if %errorlevel% neq 0 (
echo [ERROR] 虚拟环境创建失败
pause
exit /b 1
)
echo [SUCCESS] 虚拟环境创建成功
)
:: 激活虚拟环境
echo [INFO] 正在激活虚拟环境...
call venv\Scripts\activate.bat
if %errorlevel% neq 0 (
echo [ERROR] 虚拟环境激活失败
pause
exit /b 1
)
echo [SUCCESS] 虚拟环境已激活
:: 检查依赖是否已安装
echo [INFO] 检查Python依赖...
if exist "requirements.txt" (
python -c "import flask, flask_socketio, cv2, mediapipe" >nul 2>&1
if %errorlevel% neq 0 (
echo [WARNING] 依赖未完全安装,正在安装...
pip install -r requirements.txt
if %errorlevel% neq 0 (
echo [ERROR] 依赖安装失败
pause
exit /b 1
)
echo [SUCCESS] 依赖安装成功
) else (
echo [SUCCESS] 依赖已安装
)
) else (
echo [ERROR] requirements.txt 文件不存在
pause
exit /b 1
)
:: 检查必要文件是否存在
echo [INFO] 检查必要文件...
set "files=run_web_service.py src\web_server.py src\hand_detection_3d.py templates\index.html"
for %%f in (%files%) do (
if not exist "%%f" (
echo [ERROR] 缺少必要文件: %%f
pause
exit /b 1
)
)
echo [SUCCESS] 所有必要文件存在
:: 解析命令行参数
set HOST=0.0.0.0
set PORT=5000
set DEBUG=
set TEST_VIDEO=
:parse_args
if "%~1"=="" goto :end_parse
if "%~1"=="--host" (
set HOST=%~2
shift
shift
goto :parse_args
)
if "%~1"=="--port" (
set PORT=%~2
shift
shift
goto :parse_args
)
if "%~1"=="--debug" (
set DEBUG=--debug
shift
goto :parse_args
)
if "%~1"=="--test-video" (
set TEST_VIDEO=--test-video %~2
shift
shift
goto :parse_args
)
if "%~1"=="-h" goto :show_help
if "%~1"=="--help" goto :show_help
if "%~1"=="/?" goto :show_help
echo [ERROR] 未知参数: %~1
echo 使用 %~nx0 --help 查看帮助
pause
exit /b 1
:show_help
echo 用法: %~nx0 [选项]
echo.
echo 选项:
echo --host HOST 服务器地址 (默认: 0.0.0.0)
echo --port PORT 端口号 (默认: 5000)
echo --debug 启用调试模式
echo --test-video VIDEO 使用本地测试视频
echo -h, --help, /? 显示帮助信息
echo.
echo 示例:
echo %~nx0 # 基本启动
echo %~nx0 --host localhost --port 8080 # 自定义地址和端口
echo %~nx0 --debug # 调试模式
echo %~nx0 --test-video data\videos\test.mp4 # 本地视频测试
pause
exit /b 0
:end_parse
:: 显示启动信息
echo.
echo [INFO] 启动配置:
echo - 服务器地址: %HOST%
echo - 端口号: %PORT%
if not "%DEBUG%"=="" (
echo - 调试模式: 启用
)
if not "%TEST_VIDEO%"=="" (
echo - 测试视频: %TEST_VIDEO:~13%
)
echo.
:: 显示访问地址
if "%HOST%"=="0.0.0.0" (
echo [INFO] 服务启动后可通过以下地址访问:
echo - 本地访问: http://localhost:%PORT%
for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "IPv4"') do (
set IP=%%i
set IP=!IP: =!
echo - 局域网访问: http://!IP!:%PORT%
goto :continue
)
:continue
) else (
echo [INFO] 服务启动后访问地址: http://%HOST%:%PORT%
)
echo.
echo [INFO] 按 Ctrl+C 停止服务
echo ================================================
echo.
:: 启动服务
echo [INFO] 正在启动手部检测Web服务...
python run_web_service.py --host %HOST% --port %PORT% %DEBUG% %TEST_VIDEO%
pause