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