Lane tracking- matlab

CU-ICAR COURSE project.

 

 

lane track

pic=imread('F:\machine learning\Lanetrack\test.png');
imshow(pic)
grapy_pic=rgb2gray(pic);
edge_pic=edge(grapy_pic,'canny',[0.05 0.35]);
imshow(edge_pic)

 

region mask
 

shape=size(pic);
% row coordinate
a=[shape(2)*0.4 shape(2)*1 shape(2)*1 shape(2)*0.2];
%column corordinate
b=[shape(1)*0.55 shape(1)*0.5 shape(1) shape(1)];
bw=roipoly(pic,a,b);
BW=(edge_pic(:,:,1) & bw);
imshow(BW)

RGB = insertShape(pic,'Rectangle',a,'LineWidth',5);
imshow(RGB)

different a and b

RGB = insertShape(pic,'Rectangle',b,'LineWidth',5);
imshow(RGB)

hough transform to get line


y=mx+b

[H, T, R]=hough(BW);
P=houghpeaks(H,3);
lines=houghlines(BW,T,R,P,'FillGap',4,'MinLength',5);
imagesc(pic);
hold on;
plot(lines(5).point1(1),lines(5).point1(2),'rd')
for i=1:length(lines)
%    plot(lines(i).point1(1),lines(i).point1(2),'Color','red','LineWidth',10); hold on;
% %  
%   plot(lines(i).point2(1),lines(i).point2(2),'Color','red','LineWidth',10); hold on;
   
  plot([lines(i).point1(1),lines(i).point2(1)],[lines(i).point1(2),lines(i).point2(2)],'Color','blue','LineWidth',4)
end

so many lines, you should merge it.

anglethres=0.01; %separate left/right by orientation threshold
leftlines=[];rightlines=[]; %Two group of lines
for k = 1:length(lines)
x1=lines(k).point1(1);y1=lines(k).point1(2);
x2=lines(k).point2(1);y2=lines(k).point2(2);
if (x2>=shape(2)/2) && ((y2-y1)/(x2-x1)>anglethres)
rightlines=[rightlines;x1,y1;x2,y2];
elseif (x2<=shape(2)/2) && ((y2-y1)/(x2-x1)<(-1*anglethres))
leftlines=[leftlines;x1,y1;x2,y2];
end
end
draw_y=[shape(1)*0.6,shape(1)]; %two row coordinates
PL=polyfit(leftlines(:,2),leftlines(:,1),1);
draw_lx=polyval(PL,draw_y); %two col coordinates of left line
PR=polyfit(rightlines(:,2),rightlines(:,1),1);
draw_rx=polyval(PR,draw_y); %two col coordinates of right line
imagesc(pic);
hold on;
plot(draw_lx,draw_y,'LineWidth',2,'Color','red');
hold on
plot(draw_rx,draw_y,'LineWidth',2,'Color','red');

p = polyfit(x,y,n) returns the coefficients for a polynomial p(x) of degree n that is a best fit (in a least-squares sense) for the data in y. The coefficients in p are in descending powers, and the length of p is n+1
during the program, use polyfit(y,x,1), then specify the coordinates of y, and you can get the x by polyval. thus use (x,y) coordinates you can get the lane line.

During the project, noise (light) will add in the picture, so you need use kalman filter to stable your tacking lane.

Before controlling the AV, you should transform to vehicle coordinates.

 

 

 

 

I will continue after the experement

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个码农都是奢望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值