%%%%%%%%%绝缘纸平行竖直测量%%%%%%%
I=imread('C:\Users\weixing\Desktop\17AM\11.10\59.png');
I= imcrop(I,[410 243 55 217]);%分割出第一个温控器
I=im2bw(I,0.7);%图像二值化
h=fspecial('gaussian',3,1.8);%sigma=1.8的3*3高斯模板
I=imfilter(I,h);%进行高斯平滑滤波
BW=edge(I,'canny');
%执行Hough变换并显示Hough矩阵
[H,T,R]=hough(BW);
%在Hough矩阵中寻找前8个大于Hough矩阵中最大值0.3倍的峰值
P=houghpeaks(H,2,'threshold',ceil(0.3*max(H(:))));
x=T(P(:,2));y=R(P(:,1));%由行、列索引转换成实际坐标
%找到并绘制直线
lines=houghlines(BW,T,R,P,'FillGap',100,'MinLength',20);%合并距离小于5的线段,丢弃所有长度小于7的直线段
for k=1:length(lines)%依次标出各条直线段
xy=[lines(k).point1;lines(k).point2];
end
if (k==2)
%获得两条线段端点的坐标
x1y1=[lines(1).point1;lines(1).point2];
x2y2=[lines(2).point1;lines(2).point2];
%判断绝缘纸是否竖直
if(abs(x1y1(1,1)-x1y1(2,1))<=10&&abs(x2y2(1,1)-x2y2(2,1))<=10)
jyz1=1;
else
jyz1=0;
end
else
jyz1=0;
end
%%%%%%%%%%%管脚长度和绝缘纸长度测量%%%%%%%%%%%
I=imread('C:\Users\weixing\Desktop\17AM\11.10\59.png');
I1= imcrop(I,[360 190 150 290]);
A1=zeros(8,2);
B1=zeros(2,2);
i=1;
x=46;
for y=1:80
if(I1(y,x)>=I1(y+1,x))
m=I1(y,x)-I1(y+1,x);
else
m=I1(y+1,x)-I1(y,x);
end
if(m>25)
B1(1,1)=x;
B1(1,2)=y;
if( abs(B1(2,2)-B1(1,2))>10)
B1(2,1)=x;
B1(2,2)=y;
A1(i,1)=x;
A1(i,2)=y;
i=i+1;
end
end
end
A1(i,1)=x;
A1(i,2)=A1(i-1,2)+167;
i=i+1;
for y=250:290
if(I1(y,x)>=I1(y+1,x))
m=I1(y,x)-I1(y+1,x);
else
m=I1(y+1,x)-I1(y,x);
end
if(m>25)
B1(1,1)=x;
B1(1,2)=y;
if(abs(B1(2,2)-B1(1,2))>10)
B1(2,1)=x;
B1(2,2)=y;
A1(i,1)=x;
A1(i,2)=y;
i=i+1;
end
end
end
x=116;
for y=1:60
if(I1(y,x)>=I1(y+1,x))
m=I1(y,x)-I1(y+1,x);
else
m=I1(y+1,x)-I1(y,x);
end
if(m>25)
B1(1,1)=x;
B1(1,2)=y;
if( abs(B1(2,2)-B1(1,2))>10)
B1(2,1)=x;
B1(2,2)=y;
A1(i,1)=x;
A1(i,2)=y;
i=i+1;
end
end
end
for y=250:290
if(I1(y,x)>=I1(y+1,x))
m=I1(y,x)-I1(y+1,x);
else
m=I1(y+1,x)-I1(y,x);
end
if(m>25)
B1(1,1)=x;
B1(1,2)=y;
if(abs(B1(2,2)-B1(1,2))>10)
B1(2,1)=x;
B1(2,2)=y;
A1(i,1)=x;
A1(i,2)=y;
i=i+1;
end
end
end
j=1;
for i=1:8
if(A1(i,1)==46)
j=j+1 ;
end
end
if(abs(A1(1,2)-A1(j,2))<10)
gjcd1=1;
else
gjcd1=0;
end
if(abs(A1(3,2)-A1(2,2))>16&&abs(A1(3,2)-A1(7,2))>16&&abs(A1(4,2)-A1(5,2))>16&&abs(A1(4,2)-A1(8,2))>16)
jyzcd1=1;
else
jyzcd1=0;
end
|