資源簡介
使用MATLAB實現(xiàn)Hough變換,檢測車道線的demo程序

代碼片段和文件信息
I??=?imread(‘road.jpg‘);
I?=?rgb2gray(I);
BW?=?edge(I‘canny‘);
[HTR]?=?hough(BW‘RhoResolution‘0.5‘Theta‘-90:0.5:89.5);
imshow(H[]‘XData‘T‘YData‘R‘InitialMagnification‘‘fit‘);
xlabel(‘\theta‘)?ylabel(‘\rho‘);
axis?on?axis?normal?hold?on;
P??=?houghpeaks(H50‘threshold‘ceil(0.3*max(H(:))));
x?=?T(P(:2));
y?=?R(P(:1));
plot(xy‘s‘‘color‘‘white‘);
%?Find?lines?and?plot?them
lines?=?houghlines(BWTRP‘FillGap‘7‘MinLength‘100);
figure?imshow(I)?hold?on
max_len?=?0;
for?k?=?1:length(lines)
????xy?=?[lines(k).point1;?lines(k).point2];
????plot(xy(:1)xy(:2)‘LineWidth‘2‘Color‘‘green‘);
????
????%?plot?beginnings?and?ends?of?lines
????plot(xy(11)xy(12)‘x‘‘LineWidth‘2‘Color‘‘yellow‘);
????plot(xy(21)xy(22)‘x‘‘LineWidth‘2‘Color‘‘red‘);
????
????%?determine?the?endpoints?of?the?longest?line?segment
????len?=?norm(lines(k).point1?-?lines(k).point2);
????if?(?len?>?max_len)
????????max_len?=?len;
????????xy_long?=?xy;
????end
end
%?highlight?the?longest?line?segment
plot(xy_long(:1)xy_long(:2)‘LineWidth‘2‘Color‘‘cyan‘);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1117??2016-04-15?13:29??hough_line.m
?????文件??????24847??2016-04-15?13:25??road.jpg
?????文件??????46532??2016-04-15?13:28??result.jpg
?????文件??????27491??2016-04-15?13:28??hough.jpg
-----------?---------??----------?-----??----
????????????????99987????????????????????4
- 上一篇:極限學習機ELM的最簡單實用代碼
- 下一篇:攝影測量空間后方交會 matlab編程
評論
共有 條評論