當前位置:編程學習大全網 - 網站源碼 - matlab實現hough變換檢測直線

matlab實現hough變換檢測直線

clear all;

clc;

r = imread('C:\Users\lenovo\Desktop\canny.jpg');

t=rgb2gray(r);

figure,imshow(t)

f=edge(t,'canny');

figure,imshow(f)

[H, theta, rho] = hough(f,'RhoResolution',0.5,'Theta',-90:0.5:89.5);

figure

imshow(imadjust(H),'Xdata', theta, 'Ydata', rho, 'InitialMagnification','fit');

axis on, axis normal

p= houghpeaks(H, 5);

%[r,c] = houghpeaks(H, 5);

hold on;

%plot(theta(r), rho(c), 'linestyle', 'none', 'marker', 's', 'color', 'w')

plot(p, 'linestyle', 'none', 'marker', 's', 'color', 'r')

lines = houghlines(f, theta, rho,p);

%lines = houghlines(f, theta, rho, r, c);

figure,

imshow(t)

hold on

for k = 1: length(lines)

xy = [lines(k).point1; lines(k).point2];

plot(xy(:, 2), xy(:, 1), 'LineWidth', 4, 'Color', [.6, .2, .1]);

end

hold off

按上面語句試試

  • 上一篇:淘寶賣家主圖和詳情頁怎麽制作
  • 下一篇:什麽指標能反映股票的供求關系
  • copyright 2024編程學習大全網