Simulink:车道线识别

该文章介绍了使用MATLAB进行车道线识别的过程,包括图片读取、高斯滤波、颜色阈值处理、边缘检测、ROI选择以及霍夫变换检测直线,以识别黄色车道线。代码示例展示了从图像预处理到提取车道线的关键步骤,还提到了可能的扩展应用,如坐标转换和自动驾驶模型解析。
摘要由CSDN通过智能技术生成

1 博客内容

      近期看matlab(simulink)应用,关注到Github小伙伴分享的车道线识别用例,这里复盘供了解思路。作者:ysshah95,Git链接: https://github.com/ysshah95/Lane-Detection-using-MATLAB.git.

2 车道线识别过程

  1. 图片信息读取
frame=imread('pic_01.jpg')

在这里插入图片描述

在这里插入图片描述

  1. 高斯滤波
frame = imgaussfilt3(frame);

在这里插入图片描述
在这里插入图片描述
3. 提取车道线

      channel1MinYellow = 130;
      channel1MaxYellow = 255;
 
      channel2MinYellow = 130;
      channel2MaxYellow = 255;
 
      channel3MinYellow = 0;
      channel3MaxYellow = 130;
    
     %-----------Create mask based on chosen histogram thresholds-----------
     Yellow=((frame(:,:,1)>=channel1MinYellow)|(frame(:,:,1)<=channel1MaxYellow))& ...
        (frame(:,:,2)>=channel2MinYellow)&(frame(:,:,2)<=channel2MaxYellow)&...
        (frame(:,:,3)>=channel3MinYellow)&(frame(:,:,3)<=channel3MaxYellow);

白色:rgb(255,255,255)   黄色: rgb(255,255,0)

在这里插入图片描述
在这里插入图片描述
4. ROI感兴趣区域( region of interest)

c = [0 4  10 10 ]
r = [10 0 0 10]
BW = roipoly(frameOrigin,c,r);

在这里插入图片描述
在这里插入图片描述

5.车道线生成流程
在这里插入图片描述
6.车道线探测实例

在这里插入图片描述

3 代码脚本

%------    名称:  LaneDetect.m
%------    作者:  ysshah95
%------    网址:  https://github.com/ysshah95/Lane-Detection-using-MATLAB.git
%------    更新:  Morven_Xie
%------    版本:  1.0
%------    时间:  2023/3/9 23:49
%------    功能:  用于提取图片车道线(黄色)
%------    简介:  简易思路提取车道线供学习参考
%------    Email:  morven_xie@163.com


%------------------打开图片文件--------------------------------------------
frame=imread('pic_01.jpg')

%------------------高斯滤波,线性平滑--------------------------------------
frame = imgaussfilt3(frame);

%------------------设置R/G/B留存范围---------------------------------------
channel1MinY = 130;
channel1MaxY = 255;

channel2MinY = 130;
channel2MaxY = 255;

channel3MinY = 0;
channel3MaxY = 130;
    
%-----------提取图片指定色彩范围的像素区域---------------------------------
Yellow=((frame(:,:,1)>=channel1MinY)|(frame(:,:,1)<=channel1MaxY))& ...
        (frame(:,:,2)>=channel2MinY)&(frame(:,:,2)<=channel2MaxY)&...
        (frame(:,:,3)>=channel3MinY)&(frame(:,:,3)<=channel3MaxY);
figure('Name','指定区域提取-黄色车道线'), imshow(Yellow);

%-----------像素区域的边缘检测---------------------------------------------
frameY = edge(Yellow, 'canny', 0.2);
figure('Name','黄色车道线边缘检测结果'), imshow(frameY);

%-----------删除少于30个像素的所有连通分量---------------------------------
frameY = bwareaopen(frameY,30);
figure('Name','黄色车道线边缘检测去除噪点结果'), imshow(frameY);

%-----------ROI感兴趣区域(region of interest)提取-------------------------
r =[200 400 1100 1300]
c = [750 300 300 750]

roiY = roipoly(frameY, r, c);
[R , C] = size(roiY);
    for i = 1:R
        for j = 1:C
            if roiY(i,j) == 1
                frame_roiY(i,j) = frameY(i,j);
            else
                frame_roiY(i,j) = 0;  
            end
        end
    end  

figure('Name','黄色车道线ROi区域提取'), imshow(frame_roiY);

%-----------霍夫变换获得连续直线点-----------------------------------------
 [H_Y,theta_Y,rho_Y] = hough(frame_roiY);
 P_Y = houghpeaks(H_Y,2,'threshold',2);
lines_Y = houghlines(frame_roiY,theta_Y,rho_Y,P_Y,'FillGap', ...
              3000,'MinLength',20);
figure('Name','图片中获取霍夫直线'), imshow(frame), hold on
max_len = 0;
    for k = 1:length(lines_Y)
%-----------去除非预期范围夹角直线-----------------------------------------        
if(lines_Y(k).theta > 30 && lines_Y(k).theta < 150)
 xy = [lines_Y(k).point1; lines_Y(k).point2];
       plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');

 % Plot beginnings and ends of lines
       plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
       plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
end
end

4 扩展应用

      有些可研究地方:

  • 相机坐标系和车体坐标系互换;
  • 霍夫变换起点识别+滑动窗口+车道线拟合。

       有趣应用:

  • 深度解析 openpilot 自动驾驶模型,网址: https://zhuanlan.zhihu.com/p/302798977;
  • 逗号科技:Comma.ai自动驾驶,网址: https://www.bilibili.com/video/BV12x411R72b/?spm_id_from=333.999.0.0。

在这里插入图片描述

>> 更多相关内容,点击Morven_Xie博客概览

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值