hough变换检测矩形并显示

2019-07-17 12:53发布

下面是我的代码 。。。只画出线  并不能检测矩形 ,求大神指教啊 另外,我附上需检测的图片a=imread('juxing.bmp');
a=rgb2gray(a)
I=dither(a)
roti=imrotate(I,33,'crop')
BW=edge(rotI,'log');
[H,T,R]=hough(BW);
P=houghpeaks(H,18,'threshold',ceil(0.3*max(H(:))));
x=T(P(:,2));y=R(P(:,1));
lines=houghlines(BW,T,R,P,'FillGap',18,'MinLength',8);
figure,imshow(rotI),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(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
    plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
end


juxing.bmp
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。