Repository navigation
优化主函数代码 - #4250
Merged
Merged
优化主函数代码#4250
Conversation
Refactor main program for accident video recognition tool, streamline argument parsing, and enhance error handling.
donghaiwang
approved these changes
Dec 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修改概述:
优化主函数代码,新增日志管理、命令行参数控制及性能优化,提升工具的灵活性、可维护性与运行效率
修改的详细描述
1.用logging模块替代print,实现分级日志输出(支持 DEBUG/INFO/WARNING 级别),便于调试与问题追溯;
2.新增--skip-deps(跳过依赖检查)、--conf(动态调整置信度)等命令行参数,无需修改配置文件即可灵活配置工具;
3.缓存os.environ为局部变量,减少属性查找开销,提升程序运行性能;
4.增加参数合法性校验(如检测置信度的 0-1 范围校验),避免非法输入导致程序异常。
经过了什么样的测试?
操作系统:Windows 10/11;
Python 版本:Python 3.11.9;
测试场景:摄像头实时检测、本地视频文件检测,功能均正常运行。
运行效果
动图、视频、截图等程序成功启动并执行检测流程,可正常识别目标(如截图中识别到 “person” 类别),日志输出清晰(包含启动、初始化等关键步骤),检测过程稳定无异常。
