MATLAB车道偏离检测系统

MATLAB车道线识别系统

一、核心代码

function imgout = lanemarker(img)

    global top bot

    persistent tform

    if isempty(tform)

        movingPoints = [203 720; 585 460; 695 460 ; 1127 720];

        fixedPoints = [320 720; 320 0; 960 0; 960 720];

        tform = fitgeotrans(movingPoints,fixedPoints,'projective');

        top = 220;

        bot = 12;

    end

    topview = view2top(img,tform);

    [flanel,flaner] = lanefinder(topview);

    hpic = size(topview,1);

    y = 1:hpic;

    y = y';

    xl = polyval(flanel,y);

    xr = polyval(flaner,y);

    dim = size(topview);

    dim = [dim,3];

    imref = imref2d(size(topview));

    lanel = reshape([xl';y'],1,[]);

    laner = [xr';y'];

    laner = fliplr(laner);

    laner = reshape(laner,1,[]);

    xpic = zeros(dim,'uint8');

    xpic = insertShape(xpic,'FilledPolygon',[lanel,laner],'Color',[0,255,0],'Opacity',0.3);

    xpic = imwarp(xpic,tform.invert,'OutputView',imref);

    img = imlincomb(1,img,1,xpic);

    xpic = zeros(dim,'uint8');

    xpic = insertShape(xpic,'Line',lanel,'LineWidth',20,'Color',[255,0,0],'Opacity',1);

    xpic = insertShape(xpic,'Line',laner,'LineWidth',20,'Color',[255,0,0],'Opacity',1);

    xpic = imwarp(xpic,tform.invert,'OutputView',imref);

    imgout = imlincomb(1,img,1,xpic);

end

上面是主程序view2top函数是将图转换为俯视图的函数,就是由左图变成右边的图。view2top函数由很多函数来完成工作,下面做一些必要说明。

function topview = view2top(img,tform)

    global top bot

    th_sobelx = [35, 100];

    th_sobely= [30, 255];

    th_mag = [30, 255];

    th_dir =  [0.7, 1.3];

    th_h = [10, 100];

    th_s = [85, 255];

    th_l = [0, 60];

    gradient_comb = gradient_combine(img, th_sobelx, th_sobely, th_mag, th_dir);

    hsl_comb = hsl_combine(img, th_h, th_s, th_l);

    dim = size(img);

    combined_result = zeros(dim(1:2));

    combined_result = uint8(combined_result);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值