Matlab直线检测示例程序

    xiaoxiao2022-07-03  116

    写在前面的话:文章内容来源于但不限于网络、书籍、个人心得体会等,意在总结和方便各位同行快速参考,共同学习进步,记录自己的问题。错误在所难免,有请各位批评斧正。如有侵权,烦请第一时间通知,我会立即删除相关内容,万分感谢!

     Hough变换小程序,拿去学习吧,时间久了,可能有错误。

    I= imread('2.png'); BW1=im2bw(I,0.95); BW2=double(BW1); BW3=edge(BW2,'sobel'); [H,T,R]=hough(BW3); imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit'); xlabel('\theta');ylabel('\rho'); axis on,axis normal,hold on; P=houghpeaks(H,5,'threshold',ceil(0.3*max(H(:)))); x=T(P(:,2));y=R(P(:,1)); plot(x,y,'s','color','white'); lines=houghlines(BW3,T,R,P,'FillGap',5,'MinLength',7); figure,imshow(BW3),hold on; In images.internal.initSize (line 71) In imshow (line 336) 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(xy(1,1),xy(1,2),'x''lineWidth',2,'Color','yellow'); plot(xy(2,1),xy(2,2),'x''lineWidth',2,'Color','red'); len=norm(lines(k).point1-lines(k).point2); if(len>max_len) max_len=len; xy_long=xy; end end plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','cyan');

     

    最新回复(0)