代码拉取完成,页面将自动刷新
function [thetaz]=LL_angle2(img,x,y)
rc=0;thetaz=0;
while thetaz==0
if rc~=0
img=imrotate(img,rc);
end
[imgN,imgM]=size(img);
image=zeros(imgN,imgM);
R=width(x,y,img);
r=10*R;
for i=1:imgN %行
for j=1:imgM %列
if sqrt((j-x)^2+(i-y)^2)<r
image(i,j)=~img(i,j);
end
end
end
BW=bwmorph(image,'thin',Inf);
[H,theta,rho]= hough(BW);
P = houghpeaks(H,7,'threshold',ceil(0.4*max(H(:))));%检测投票结果
lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',7);%检测直线
for k = 1:length(lines)
len = norm(lines(k).point1 - lines(k).point2);%直线的长度
a(k)=len;
[~,t]=sort(a);
end
N=min(3,length(lines));thetax=zeros(1,N);
for i=1:N
thetax(i)=lines(t(length(t)-(i-1))).theta;
end
figure;subplot(121);imshow(BW);
subplot(122);imshow(BW);
hold on;
for i=1:N
xy{i}= [lines(t(length(t)-(i-1))).point1; lines(t(length(t)-(i-1))).point2];
plot(xy{i}(:,1),xy{i}(:,2),'LineWidth',2,'Color','blue')
end
temp=median(thetax);
n0=0;
for i=1:N
if(abs(thetax(i)-temp)<=15)
xtx(i)=thetax(i);
n0=n0+1;
else
xtx(i)=0;
end
end
if n0==N
thetaz=sum(xtx)/n0+rc;
if thetaz<-60
thetaz=thetaz+180;
end
else
thetaz=0;
end
rc=rc+10;
end
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。