diff --git a/src/Driving_Accident_Video_Recognition/main.py b/src/Driving_Accident_Video_Recognition/main.py index eab5ee954a..073a804427 100644 --- a/src/Driving_Accident_Video_Recognition/main.py +++ b/src/Driving_Accident_Video_Recognition/main.py @@ -1,55 +1,41 @@ """ -主程序入口:整合所有模块,支持命令行参数控制 +主程序:驾驶事故视频识别工具 """ import sys import os -import argparse # 新增:导入命令行解析模块 -# 关键:将当前脚本所在目录加入Python模块搜索路径 +import argparse + +# 确保当前目录可被搜索 current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(current_dir) -from config import REQUIRED_PACKAGES, PYPI_MIRROR, SUPPORTED_LANGUAGES -from utils.dependencies import install_dependencies -from core.detector import AccidentDetector +# 直接导入同目录的文件(彻底避免模块包问题) +from config import REQUIRED_PACKAGES, PYPI_MIRROR, PERSON_VEHICLE_DISTANCE, ACCIDENT_CONTINUOUS_FRAMES +from dependencies import install_dependencies # 直接导入同目录的dependencies.py +from detector import AccidentDetector + def parse_args(): - """新增:解析命令行参数""" - parser = argparse.ArgumentParser(description="驾驶事故视频识别工具") - # 检测源:-s/--source,支持摄像头(数字)或视频路径(字符串) - parser.add_argument( - "--source", "-s", - default=None, - help=f"检测源(0=摄像头,或视频路径如'test.mp4'),默认使用config.py配置" - ) - # 语言:-l/--lang,支持中文(zh)、英文(en) - parser.add_argument( - "--lang", "-l", - default="zh", - choices=SUPPORTED_LANGUAGES, - help=f"标注语言,支持{SUPPORTED_LANGUAGES},默认中文(zh)" - ) + parser = argparse.ArgumentParser(description="驾驶事故视频识别") + parser.add_argument("--source", "-s", default=0, help="检测源:0=摄像头/视频路径") + parser.add_argument("--language", "-l", default="zh", choices=["zh", "en"], help="标注语言") return parser.parse_args() + def main(): - """主函数:执行依赖安装 → 解析参数 → 启动检测""" - args = parse_args() # 新增:解析命令行参数 + args = parse_args() try: - print("🚀 启动驾驶事故视频识别工具...") - # 第一步:自动安装依赖 + print("🚀 启动驾驶事故检测...") + # 安装依赖 install_dependencies(REQUIRED_PACKAGES, PYPI_MIRROR) - # 第二步:初始化检测器 + # 启动检测 detector = AccidentDetector() - # 第三步:启动检测(传递命令行参数:检测源、语言) - detector.run_detection( - source=args.source, # 优先使用命令行指定的检测源 - language=args.lang # 传递语言参数 - ) + detector.run_detection(language=args.language) except KeyboardInterrupt: - print("\n🛑 用户强制中断程序") - except Exception as e: - print(f"\n❌ 程序运行出错:{e}") + print("\n🛑 程序中断") finally: - print("👋 程序正常退出") + print("👋 程序退出") + if __name__ == "__main__": - main() \ No newline at end of file + main()