​一、简介

1 应用背景 指针式机械表盘具有安装维护方便、结构简单、防电磁干扰等诸多优点, 目前广泛应用于工矿企业、能源及计量等部门。随着仪表数量的增加及精密仪表技术的发展,人工判读已经不能满足实际应用需求。随着计算机技术和图像处理技术的不断发展,指针式机械表自动读表技术应运而生。该技术提高了表盘识别的自动化程度及实时性,将代替传统工业仪表的读取方式得到广泛应用。

2 目的

(1)了解机械式表盘自动读表技术的基本原理。

(2)了解仪器表盘识别技术的基本方法和相关算法。

(3)学会利用MATLAB实现对图像的边缘检测、图像边缘锐化、二值化处理、Hough变换等图像处理技术。

3 原理 根据机械式表盘的图像特征,采用图像边缘点法线方向计数累加的圆心定位方法及过定点的直线检测算法,达到表盘识别的目标。仪表刻度检测流程如下: 摄像头采集表盘图像,送入计算机进行预处理及边缘检测操作;计算机检测出表盘回转中心及半径,并定位出表盘的有效显示区域;在此区域内,利用过定点( 回转中心)的Hough 直线变换,基于特征点对应角度的峰值搜索算法识别出指针中心线,从而输出检测结果。

4 要求

(1)读取一副仪表图片。读入图像,对图像进行预处理及边缘检测操作。

(2)采用平滑滤波法对图像进行处理,滤波的同时锐化图像的边缘。

(3)通过对读入的仪表图像进行处理,能清楚的识别表盘指针指数,且具有较准确的识别精度。

二、源代码


          
          
function varargout = code(varargin)
  • 1.

          
          
% CODE M-file for code.fig
  • 1.

          
          
% CODE, by itself, creates a new CODE or raises the existing
  • 1.

          
          
% singleton*.
  • 1.

          
          
%
  • 1.

          
          
% H = CODE returns the handle to a new CODE or the handle to
  • 1.

          
          
% the existing singleton*.
  • 1.

          
          
%
  • 1.

          
          
% CODE('CALLBACK',hObject,eventData,handles,...) calls the local
  • 1.

          
          
% function named CALLBACK in CODE.M with the given input arguments.
  • 1.

          
          
%
  • 1.

          
          
% CODE('Property','Value',...) creates a new CODE or raises the
  • 1.

          
          
% existing singleton*. Starting from the left, property value pairs are
  • 1.

          
          
% applied to the GUI before code_OpeningFunction gets called. An
  • 1.

          
          
% unrecognized property name or invalid value makes property application
  • 1.

          
          
% stop. All inputs are passed to code_OpeningFcn via varargin.
  • 1.

          
          
%
  • 1.

          
          
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  • 1.

          
          
% instance to run (singleton)".
  • 1.

          
          
%
  • 1.

          
          
% See also: GUIDE, GUIDATA, GUIHANDLES
  • 1.

          
          
% Edit the above text to modify the response to help code
  • 1.

          
          
% Last Modified by GUIDE v2.5 05-Jan-2012 20:44:26
  • 1.

          
          
% Begin initialization code - DO NOT EDIT
  • 1.

          
          
gui_Singleton = 1;
  • 1.

          
          
gui_State = struct('gui_Name', mfilename, ...
  • 1.

          
          
'gui_Singleton', gui_Singleton, ...
  • 1.

          
          
'gui_OpeningFcn', @code_OpeningFcn, ...
  • 1.

          
          
'gui_OutputFcn', @code_OutputFcn, ...
  • 1.

          
          
'gui_LayoutFcn', [] , ...
  • 1.

          
          
'gui_Callback', []);
  • 1.

          
          
if nargin && ischar(varargin{1})
  • 1.

          
          
gui_State.gui_Callback = str2func(varargin{1});
  • 1.

          
          
end
  • 1.

          
          
if nargout
  • 1.

          
          
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  • 1.

          
          
else
  • 1.

          
          
gui_mainfcn(gui_State, varargin{:});
  • 1.

          
          
end
  • 1.

          
          
% End initialization code - DO NOT EDIT
  • 1.

          
          
% --- Executes just before code is made visible.
  • 1.

          
          
function code_OpeningFcn(hObject, eventdata, handles, varargin)
  • 1.

          
          
% This function has no output args, see OutputFcn.
  • 1.

          
          
% hObject handle to figure
  • 1.

          
          
% eventdata reserved - to be defined in a future version of MATLAB
  • 1.

          
          
% handles structure with handles and user data (see GUIDATA)
  • 1.

          
          
% varargin command line arguments to code (see VARARGIN)
  • 1.

          
          
% Choose default command line output for code
  • 1.

          
          
handles.output = hObject;
  • 1.

          
          
% Update handles structure
  • 1.

          
          
guidata(hObject, handles);
  • 1.

          
          
% UIWAIT makes code wait for user response (see UIRESUME)
  • 1.

          
          
% uiwait(handles.figure1);
  • 1.

          
          
backgroundImage = importdata('yalibiao.jpg');
  • 1.

          
          
axes(handles.axes1);
  • 1.

          
          
image(backgroundImage);
  • 1.

          
          
axis off;
  • 1.

          
          
% --- Outputs from this function are returned to the command line.
  • 1.

          
          
function varargout = code_OutputFcn(hObject, eventdata, handles)
  • 1.

          
          
% varargout cell array for returning output args (see VARARGOUT);
  • 1.

          
          
% hObject handle to figure
  • 1.

          
          
% eventdata reserved - to be defined in a future version of MATLAB
  • 1.

          
          
% handles structure with handles and user data (see GUIDATA)
  • 1.

          
          
% Get default command line output from handles structure
  • 1.

          
          
varargout{1} = handles.output;
  • 1.

          
          
% --- Executes on selection change in listbox1.
  • 1.

          
          
function listbox1_Callback(hObject, eventdata, handles)
  • 1.

          
          
% hObject handle to listbox1 (see GCBO)
  • 1.

          
          
% eventdata reserved - to be defined in a future version of MATLAB
  • 1.

          
          
% handles structure with handles and user data (see GUIDATA)
  • 1.

          
          
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
  • 1.

          
          
% contents{get(hObject,'Value')} returns selected item from listbox1
  • 1.

          
          
% --- Executes during object creation, after setting all properties.
  • 1.

          
          
function listbox1_CreateFcn(hObject, eventdata, handles)
  • 1.

          
          
% hObject handle to listbox1 (see GCBO)
  • 1.

          
          
% eventdata reserved - to be defined in a future version of MATLAB
  • 1.

          
          
% handles empty - handles not created until after all CreateFcns called
  • 1.

          
          
% Hint: listbox controls usually have a white background on Windows.
  • 1.

          
          
% See ISPC and COMPUTER.
  • 1.

          
          
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  • 1.

          
          
set(hObject,'BackgroundColor','white');
  • 1.

          
          
end
  • 1.

点击并拖拽以移动

三、运行结果

指针式表盘识别matlab源码_图像识别_02点击并拖拽以移动

四、备注

指针式表盘识别matlab源码_图像识别_04