You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

修改YOLO代码实现车道检测未生效,求助排查问题

问题分析与修复方案

1. 参数定义错误

你添加的--lane_detection参数未设置action='store_true',导致它默认是需要接收值的参数。如果运行时仅输入--lane_detection会触发参数错误;若未传值,args.lane_detection会是None,车道检测分支根本不会执行。

修改参数定义:

parser.add_argument("--lane_detection", action='store_true', help="activate lane detection utility")

2. 变量未初始化与赋值错误

车道检测分支中使用了未定义的img变量,应该用image_detection返回的image变量,且需将处理后的结果重新赋值给image,否则后续显示的还是原始的image_resized。同时注意颜色空间转换:image_detection返回的是RGB格式图像,OpenCV默认用BGR处理,需要先转换。

修改main函数中的车道检测分支:

if args.lane_detection:
    image, detections = image_detection(
        image_name, network, class_names, class_colors, args.thresh, is_lane_detection=True
    )
    # 转换为OpenCV的BGR格式
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    for label, confidence, bbox in detections:
        # 修正变量名,将处理后的图像重新赋值
        centers, image = utils.draw_centers(image, bbox, class_colors[label])
        lines, image = utils.probabilistic_hough_transform(image, 10, 5, 100, 75, 105, 60)

3. 无需重新编译C++项目

你修改的darknet_images.py是Python脚本,直接运行即可生效,不需要重新编译Darknet的C++部分。之前的编译操作是多余的,确保运行的是你修改后的Python脚本即可。

4. 逻辑冗余优化(可选)

main函数中的两个if分支可合并为if-else,避免逻辑混乱:

if args.lane_detection:
    # 车道检测分支代码
else:
    # 原检测分支代码

内容的提问来源于stack exchange,提问作者dzakyadlh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 02:29:59