✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
⛄ 内容介绍
目前压力仪表计量读数以人工读数为主,存在读取数值偏差问题,通过计算机自动识别压力表示数代替人工读数,可提高读数精度和工作效率,进而实现无人工操作的实时监测.为实现压力仪表的自动化精准高效读数,研究了基于Hough变换算法的计算机视觉读数,开发了相应的程序.首先采集压力表示数变化照片,通过Hough变换检测圆形表盘,采用二值化算法进行前期预处理,然后进行指针细化,将呈现长三角形的指针细化成一条直线,并通过Hough变换检测直线确定细化后的指针所在象限位置以及斜率,根据斜率判断指针偏转角度,并采用最小二乘法拟合压力值与偏转角度的关系,最终计算出指针在任意位置时的压力表示值.实验结果显示:采用该方法的判读值与压力表实际示值的误差在-0.17~+0.21 MPa之间,证明了算法的有效性.
⛄ 部分代码
clc,clear all ,close all;
circleParaXYR=[];
resultPoints=[];
I_RGB = imread('3.png');
[m,n,l] = size(I_RGB);
if l>1
I = rgb2gray(I_RGB);
end
thresh=[0.1,0.2];
sigma=2;%定义高斯参数
BW = edge(double(I),'canny',thresh,sigma);
% 圆形检测参数
step_r = 1;
step_angle = 0.1;
% 最小半径
minr = 100;
% 最大半径
maxr = 500;
thresh = 0.51;
tic;
remove_long_distance(index1)=lines_remove_short(kk);
index1=index1+1;
end
end
resultPoints=lines_remove_long_distance;
end
%表达式
xy_result1=[resultPoints(1).point1;resultPoints(1).point2];
x1_result1=xy_result1(1,1);
y1_result1=xy_result1(1,2);
x2_result1=xy_result1(2,1);
y2_result1=xy_result1(2,2);
fx1=polyfit([x1_result1,x2_result1],[y1_result1,y2_result1],1);
%表达式
xy_result2=[resultPoints(2).point1;resultPoints(2).point2];
x1_result2=xy_result2(1,1);
y1_result2=xy_result2(1,2);
x2_result2=xy_result2(2,1);
y2_result2=xy_result2(2,2);
fx2=polyfit([x1_result2,x2_result2],[y1_result2,y2_result2],1);
%方程组求解
x_result=(fx2(2)-fx1(2))/(fx1(1)-fx2(1));
y_result=fx1(1)*x_result+fx1(2);
%画出最终结果
for sss=1:length(resultPoints)
xy=[resultPoints(sss).point1;resultPoints(sss).point2];
plot(xy(:,1),xy(:,2),'LineWidth',4,'Color',[1 0 0]);
end
%画出针尖位置
re=[center_circle;x_result, y_result];
plot(re(:,1),re(:,2), 'LineWidth',4,'Color',[0 1 0]);
%获取最小最大刻度坐标
resultXY=getMinMaxLocation(center_circle,I_RGB);
%获取成对区域失败
if(isempty(resultXY))
disp('获取最小最大刻度坐标失败,因为未找到成对区域!');
return;
end
%画出最小最大刻度
re2=[center_circle;resultXY(:,1)'];
plot(re2(:,1),re2(:,2), 'LineWidth',4,'Color',[0 1 0]);
re3=[center_circle;resultXY(:,2)'];
plot(re3(:,1),re3(:,2), 'LineWidth',4,'Color',[0 1 0]);
%读数 圆心坐标,针尖坐标、最小最大刻度坐标
c=[center_circle(1),center_circle(2)];
jian=[x_result,y_result];
%判断那个点为最小最大刻度
if(resultXY(2,1)<resultXY(2,2))
shang=resultXY(:,1)';
xia=resultXY(:,2)';
else
shang=resultXY(:,2)';
xia=resultXY(:,1)';
end
aerfa=acos((len_c_jian^2+len_c_shang^2-len_jian_shang^2)/(2*len_c_jian*len_c_shang));%弧度
aerfa=rad2deg(aerfa);%弧度转为度
len_c_xia=sqrt((c(1)-xia(1))^2+(c(2)-xia(2))^2);
len_shang_xia=sqrt((shang(1)-xia(1))^2+(shang(2)-xia(2))^2);
beita=acos((len_c_shang^2+len_c_xia^2-len_shang_xia^2)/(2*len_c_shang*len_shang_xia));%弧度
beita=rad2deg(beita)/2;%弧度转为度
Vmax=10;Vmin=0;
sita=(Vmax-Vmin)-((Vmax-Vmin)/((180-beita)*2))*aerfa;
disp('仪表示数=');
disp(sita);
⛄ 运行结果
⛄ 参考文献
[1] 蔡文超,于骞,王宏,等.基于快速Hough变换的圆形仪表的检测与读取[C]//中国人工智能学会第10届全国学术年会.0[2023-07-08].
[2] 冯养杰,林小竹.基于改进Hough变换的指针式仪表自动识别方法研究[J].北京印刷学院学报, 2015, 23(4):5.DOI:CNKI:SUN:BYXB.0.2015-04-023.
[3] 李勇.指针式表盘的自动识别技术研究及实现[D].郑州大学,2016.