【图像识别】基于计算机视觉实现路面裂缝检测识别系统matlab代码

1 简介

随着公路与铁路事业的飞速发展,各类车辆和里程的增加,铁路的一次次提速,都对路面产生了巨大的压力。不论是公路路面还是铁路路面,路面裂纹都能随处可见,由路面裂纹造成的交通事故时有发生。研究路面裂纹检测方法对于路面维护、交通安全具有极其重大意义。近年来,路面裂纹检测大多采用基于图像特性的方法和基于机器学习的方法。基于图像特性的方法包括边缘检测,直方图分析和形态学方法等,这类方法虽可以达到快速检测,但需手工设置较多阈值,对不同数据集甚至同一数据集的不同图像需要设置不同阈值,严重依赖于阈值的选取。而最近几年,大量学者采用基于有监督学习方式进行裂纹检测,如支持向量机、神经网络、结构化随机森林等,这种方法一般需要先对特征进行标记,然后再通过模型进行训练,可以大大提高裂纹检测的准确率,但缺点是检测效果依赖于数据集的选取,学习速度慢,因此算法难以被推广。实际上,裂纹检测需要同时兼顾性能和效率,为此,本文主要针对无监督的路面裂纹检测方法进行研究,在保证性能的前提下,提高裂纹检测的效率。本文的主要工作有:(1)提出了自适应的无监督裂纹检测方法。为了克服有监督学习适应性和推广能力差的问题,研究了基于块的无监督裂纹检测方法,具有速度快,自适应性好,易于推广到不同类型的线路等优点。但是也存在着误检和漏检等问题。为此,针对漏检裂纹,提出了基于上下文信息的自适应块裂纹检测方法;针对误检裂纹,提出了基于连通区域的裂纹几何特性分析方法。同时扩充数据集,不仅将算法应用于公路路面,还在铁路路面数据集上进一步验证了算法的有效性;(2)实现了路面裂纹特征表示算法,给出了路面裂纹类型划分和严重程度判定依据,并在公路和铁路测试集中进行了验证;(3)设计和实现了路面裂纹检测系统,将优化后的裂纹检测算法以及裂纹类型与严重程度划分算法应用于该系统中,并在不同数据集上进行了测试。​

2 部分代码

function varargout = Gui_Main(varargin)
% GUI_MAIN M-file for Gui_Main.fig
%     GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
%     singleton*.
%
%     H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
%     the existing singleton*.
%
%     GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
%     function named CALLBACK in GUI_MAIN.M with the given input arguments.
%
%     GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the
%     existing singleton*. Starting from the left, property value pairs are
%     applied to the GUI before Gui_Main_OpeningFcn gets called. An
%     unrecognized property name or invalid value makes property application
%     stop. All inputs are passed to Gui_Main_OpeningFcn via varargin.
%
%     *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
%     instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Gui_Main

% Last Modified by GUIDE v2.5 29-Mar-2011 22:28:58

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
  'gui_Singleton', gui_Singleton, ...
  'gui_OpeningFcn', @Gui_Main_OpeningFcn, ...
  'gui_OutputFcn', @Gui_Main_OutputFcn, ...
  'gui_LayoutFcn', [] , ...
  'gui_Callback',   []);
if nargin && ischar(varargin{1})
  gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
  [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
  gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Gui_Main is made visible.
function Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject   handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Gui_Main (see VARARGIN)

% Choose default command line output for Gui_Main
handles.output = hObject;
handles.Result = [];%定义结果变量
handles.File = [];%定义文件路径变量
% Update handles structure
guidata(hObject, handles);%传递参数
clc; warning off all;%清除命令行,警告
InitAxes(handles);%初始化坐标轴

% UIWAIT makes Gui_Main wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject   handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbuttonOpenFile.
function pushbuttonOpenFile_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonOpenFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
  '*.*','All Files' },'载入图像',...
  fullfile(pwd, 'images'));%选择打开文件
if isequal(filename, 0) || isequal(pathname, 0)
  return;%如果文件没选中,重新选择
end
I = imread(fullfile(pathname, filename));%读取图像
Result = Process_Main(I);%进行图像处理
handles.File = fullfile(pathname, filename);%保存路径
handles.Result = Result;%保存结果
guidata(hObject, handles);%传递数据
InitAxes(handles)%初始化坐标轴
axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示


% --- Executes on button press in pushbuttonHisteq.
function pushbuttonHisteq_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonHisteq (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
  axes(handles.axes2); imshow(handles.Result.hist); title('直方图均衡化图像');%图像显示
end



% --- Executes on button press in pushbuttonMedfilt.
function pushbuttonMedfilt_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonMedfilt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
  axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');%图像显示
end


% --- Executes on button press in pushbuttonBw.
function pushbuttonBw_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonBw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示
  axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');%图像显示
end

% --- Executes on button press in pushbuttonEnance.
function pushbuttonEnance_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonEnance (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示
  axes(handles.axes2); imshow(handles.Result.Enance); title('增强图像');%图像显示
end

% --- Executes on button press in pushbuttonBwfilter.
function pushbuttonBwfilter_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonBwfilter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示
  axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');%图像显示
  axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');%图像显示
end

% --- Executes on button press in pushbuttonCrackRec.
function pushbuttonCrackRec_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonCrackRec (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示
  axes(handles.axes2); imshow(handles.Result.Bw); title('二值图像');%图像显示
  axes(handles.axes3); imshow(handles.Result.BwFilter); title('二值图像滤波');%图像显示
  axes(handles.axes4); imshow(handles.Result.CrackRec); title('裂缝识别');%图像显示
end


% --- Executes on button press in pushbuttonCrackJudge.
function pushbuttonCrackJudge_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonCrackJudge (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示
  axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');%图像显示
  axes(handles.axes3); imshow(handles.Result.CrackRec); title('裂缝识别');%图像显示
  axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝判断');%图像显示
end

% --- Executes on button press in pushbuttonCrackLoc.
function pushbuttonCrackLoc_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonCrackLoc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示
  axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');%图像显示
  axes(handles.axes3); imshow(handles.Result.CrackJudge); title(handles.Result.str);%图像显示
  axes(handles.axes4); imshow(handles.Result.CrackJudge); title('裂缝标记图像');%图像显示
  hold on;
  rectangle('Position', handles.Result.rect, 'EdgeColor', 'g', 'LineWidth', 2);%标记矩形框
  hold off;
end

% --- Executes on button press in pushbuttonProject.
function pushbuttonProject_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonProject (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');%图像显示
  axes(handles.axes2); imshow(handles.Result.CrackJudge); title('裂缝图像');%图像显示
  axes(handles.axes3); plot(1:size(handles.Result.Image, 1), handles.Result.Projectr);%画出行投影
  title('行投影');
  axes(handles.axes4); plot(1:size(handles.Result.Image, 2), handles.Result.Projectc);%画出列投影
  title('列投影');
end


% --- Executes on button press in pushbuttonClose.
function pushbuttonClose_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonClose (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
choice = questdlg('确定退出?', ...
  '退出', ...
  '是','否','否');
switch choice
  case '是'
      close;
  otherwise
      return;
end



% --- Executes on button press in pushbuttonSaveResult.
function pushbuttonSaveResult_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonSaveResult (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
try
  if ~isempty(handles.File)
      raw = [];
      xlsfile = fullfile(pwd, 'Result/result.xls');
      if exist(xlsfile, 'file')
          [num, txt, raw] = xlsread(xlsfile);
      end
       
      F = [];
      F{1, 1} = '文件名';
      F{1, 2} = '阈值信息';
      F{1, 3} = '面积信息';
      F{1, 4} = '长度信息';
      F{1, 5} = '最大宽度信息';
      F{1, 6} = '最小宽度信息';
      F{1, 7} = '形状信息';
       
      F{2, 1} = handles.File;
      F{2, 2} = handles.Result.BwTh;
      F{2, 3} = handles.Result.BwArea;
      F{2, 4} = handles.Result.BwLength;
      F{2, 5} = handles.Result.BwWidthMax;
      F{2, 6} = max(handles.Result.BwWidthMin,0.01);
      F{2, 7} = handles.Result.str;
       
      F = [raw; F];
      xlswrite(xlsfile, F);
       
      msgbox('保存结果成功!', '信息提示框');
  end
catch
  msgbox('保存结果失败,请检查程序!', '信息提示框');
end


% --- Executes on button press in pushbuttonBridge.
function pushbuttonBridge_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonBridge (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.Result)
  axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
  axes(handles.axes2); imshow(handles.Result.BwFilter); title('二值图像滤波');
  axes(handles.axes3); imshow(handles.Result.CrackJudge); title('裂缝判断');
  axes(handles.axes4); imshow(handles.Result.CrackBridge); title('裂缝拼接');
end


% --- Executes on button press in pushbuttonSaveImage.
function pushbuttonSaveImage_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonSaveImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
  '*.*','All Files' },'Save Image',...
  fullfile(pwd, 'Result/result.png'));%选择图像保存路径
if ~isequal(filename, 0)
  imwrite(handles.Result.BwEnd, fullfile(pathname, filename));%写出图像
  msgbox('保存图像成功!', '信息提示框');%提示框
end


% --- Executes on button press in pushbuttonDiplay.
function pushbuttonDiplay_Callback(hObject, eventdata, handles)
% hObject   handle to pushbuttonDiplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
if ~isempty(handles.File)%图像信息是否为空
  F = [];
  F{1} = sprintf('文件名:%s', handles.File);
  F{2} = sprintf('阈值信息%.2f', handles.Result.BwTh);
  F{3} = sprintf('面积信息%.2f', handles.Result.BwArea);
  F{4} = sprintf('长度信息%.2f', handles.Result.BwLength);
  F{5} = sprintf('最大宽度信息%.2f', handles.Result.BwWidthMax);
  F{6} = sprintf('最小宽度信息%.2f', max(handles.Result.BwWidthMin,0.01));
  F{7} = sprintf('形状信息%s', handles.Result.str);
  listdlg('PromptString', '参数显示:',...
      'Name', '参数信息', ...
      'ListSize', [300, 150], ...
      'SelectionMode','single',...
      'ListString', F);
end

3 仿真结果

4 参考文献

[1]张旭. 基于计算机视觉的智能化道路裂缝检测系统研究[D]. 华中师范大学.

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab科研辅导帮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值