资源简介

MATLAB识别指针式仪表的示数,所用方法为距离法,经过试验,该方法可以较为准确的识别指针式仪表的示数,代码中有详细的备注,便于读者理解

资源截图

代码片段和文件信息

function ScaleBW=Dec_3th_getscale(zeroRGB)
%获得刻度二值图函数输入指零24位bmp图像输出刻度二值图
ScaleGray = rgb2gray(zeroRGB);

%ScaleGray=medfilt2(ScaleGray);%中值滤波会对刻度有损害
[mn]=size(ScaleGray);

%剪切刻度附近区域来求二值化阈值
 for i=1:0.4*m
     for j=1:0.7*n
         tempGray(ij)=ScaleGray(0.15*m+i0.15*n+j);
     end
 end
level = graythresh(tempGray);%最大类间方差法求阈值
ScaleBW = im2bw(ScaleGraylevel*1); 
figureimshow(ScaleBW)title(‘二值化‘);  %二值化结果

%去除最上边阴影
for i=1:10
    for j=1:n
        ScaleBW(ij)=1;
    end
end

ScaleBW=~ScaleBW;
figureimshow(ScaleBW)title(‘二值化后取反‘);%和二值化相比,也消除了最上边的阴影
MaxBW=max_label(ScaleBW);%提取出最大的连通域,也即表盘底部黑色区域
figureimshow(MaxBW)title(‘最大连通域‘);
TempBW=MaxBW;
ScaleBW=xor(ScaleBWTempBW);%xor:异或
figureimshow(ScaleBW)title(‘消除底部背景干扰‘);

ScaleBW=filter_label(ScaleBW);
%滤除左右边沿的残阴影减少干扰
%for i=1:m
%    for j=1:20
%        ScaleBW(ij)=0;
%    end
%end
%for i=1:m
%    for j=n-20:n
%        ScaleBW(ij)=0;
%    end
%end
%figureimshow(ScaleBW)title(‘滤除左右边沿的残留阴影‘);
%以纵轴投影来滤除非刻度区域
Touying=zeros(m1);
for i=1:m
    for j=1:n
        Touying(i1)=Touying(i1)+ScaleBW(ij);
    end
end
TempBW=max_label(Touying); 

for i=1:m
    if TempBW(i1)==0
        for j=1:n
            ScaleBW(ij)=0;
        end
    end
end

%滤除数字
%figureimshow(ScaleBW);
%[ScaleBW_Label0Num0]=bwlabel(ScaleBW);
%if Num0>26
%    for i=1:m
%        for j=1:n
%            if ScaleBW_Label0(ij)==Num0
%                ScaleBW(ij)=0;
%            end
%        end
%    end
%end

[ScaleBW_LabelNum]=bwlabel(ScaleBW);

low_point_i=zeros(Num1);
low_point_j=zeros(Num1);

for i=1:m
    for j=1:n
        if ScaleBW(ij)~=0
            low_point_i(ScaleBW_Label(ij)1)=i;  
            low_point_j(ScaleBW_Label(ij)1)=j;
        end
    end
end

average_difference=0; %平均落差
for t=2:Num
    average_difference=average_difference+abs(low_point_i(t)-low_point_i(t-1));
end
average_difference=average_difference/(Num-1);

current_p=2;
count_scale=1;
scale_p(count_scale1)=current_p;
for t=3:Num
    if abs(low_point_i(t1)-low_point_i(current_p1))        current_p=t;        
        count_scale=count_scale+1;
        scale_p(count_scale1)=current_p;
    end
end

for i=1:m
    for j=1:n
        if ScaleBW_Label(ij)~=0
            for t=1:count_scale
                if ScaleBW_Label(ij)==scale_p(t1)
                    ScaleBW_Label(ij)=200;
                end
            end
        end
    end
end

for i=1:m
    for j=1:n
        if ScaleBW_Label(ij)==200
            ScaleBW_Label(ij)=1;
        else
            ScaleBW_Label(ij)=0;
        end
    end
end
ScaleBW=ScaleBW_Label;%没有零刻度的刻度图像
figureimshow(ScaleBW)title(‘没有零刻度的刻度图像‘);
%flag=0;
%for i=m-35:-1:35
%    for j=35:n-35
%        if MaxBW(ij)~=0 && MaxBW(ij-4)==0 && MaxBW(ij-5)==0 && MaxBW(i+15j-6)==0 && MaxBW(ij+4)==0 && MaxBW(ij

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-05-08 10:29  指针表识别 (龚雄文)\
     文件        4076  2018-05-08 10:28  指针表识别 (龚雄文)\Dec_3th_getscale.m
     文件         351  2006-10-20 21:18  指针表识别 (龚雄文)\LevelDist.m
     文件        1601  2018-05-08 09:55  指针表识别 (龚雄文)\Otsu.m
     目录           0  2018-05-02 21:19  指针表识别 (龚雄文)\Photo\
     文件      230454  2007-02-05 21:47  指针表识别 (龚雄文)\Photo\01.bmp
     文件      230454  2007-01-06 15:46  指针表识别 (龚雄文)\Photo\02.bmp
     文件      230454  2007-01-06 15:48  指针表识别 (龚雄文)\Photo\03.bmp
     文件      230454  2007-02-05 21:45  指针表识别 (龚雄文)\Photo\101.bmp
     文件      230454  2007-02-05 21:45  指针表识别 (龚雄文)\Photo\102.bmp
     文件      230454  2007-02-05 21:46  指针表识别 (龚雄文)\Photo\108.bmp
     文件      230454  2007-02-05 21:40  指针表识别 (龚雄文)\Photo\38.bmp
     文件      230454  2007-02-05 21:41  指针表识别 (龚雄文)\Photo\40.bmp
     文件      230454  2007-02-05 21:42  指针表识别 (龚雄文)\Photo\50.bmp
     文件      230454  2007-02-05 21:42  指针表识别 (龚雄文)\Photo\59.bmp
     文件      230454  2007-02-05 21:43  指针表识别 (龚雄文)\Photo\61.bmp
     文件      230454  2007-02-05 21:43  指针表识别 (龚雄文)\Photo\63.bmp
     文件      230454  2007-02-05 21:44  指针表识别 (龚雄文)\Photo\65.bmp
     文件       39936  2007-04-04 09:35  指针表识别 (龚雄文)\Photo\Thumbs.db
     文件         654  2006-10-20 21:19  指针表识别 (龚雄文)\Scale_P_Distance.m
     文件         694  2006-12-04 21:53  指针表识别 (龚雄文)\filter_label.m
     文件        1891  2006-12-20 21:52  指针表识别 (龚雄文)\getindex.m
     文件         665  2006-12-04 21:51  指针表识别 (龚雄文)\getline.m
     文件        3268  2006-12-06 08:29  指针表识别 (龚雄文)\getresult.m
     文件        5821  2006-12-20 21:54  指针表识别 (龚雄文)\getscale.m
     文件         538  2018-05-08 09:24  指针表识别 (龚雄文)\getuA.m
     文件         617  2018-05-08 08:57  指针表识别 (龚雄文)\max_label.m
     文件        1548  2018-05-08 09:41  指针表识别 (龚雄文)\meter_read.m
     文件         105  2006-10-30 16:13  指针表识别 (龚雄文)\run.m
     文件         151  2006-11-19 16:32  指针表识别 (龚雄文)\t.m
     文件         265  2006-12-08 14:31  指针表识别 (龚雄文)\try5.m
............此处省略1个文件信息

评论

共有 条评论