function varargout = carcheck(varargin)
% CARCHECK M-file for carcheck.fig
% CARCHECK, by itself, creates a new CARCHECK or raises the existing
% singleton*.
%
% H = CARCHECK returns the handle to a new CARCHECK or the handle to
% the existing singleton*.
%
% CARCHECK('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CARCHECK.M with the given input arguments.
%
% CARCHECK('Property','Value',...) creates a new CARCHECK or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before carcheck_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to carcheck_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help carcheck
% Last Modified by GUIDE v2.5 31-May-2007 19:22:10
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @carcheck_OpeningFcn, ...
'gui_OutputFcn', @carcheck_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 carcheck is made visible.
function carcheck_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 carcheck (see VARARGIN)
% Choose default command line output for carcheck
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes carcheck wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = carcheck_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%选择打开指定图像
pnum=get(handles.listbox1,'value');
switch pnum
case 1
streetcar=imread('streetcar1.jpg');
case 2
streetcar=imread('streetcar2.jpg');
case 3
streetcar=imread('streetcar3.jpg');
otherwise
end
axes(handles.axes1);%选择坐标轴1
imshow(streetcar);%显示待识别图像
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pnum=get(handles.listbox1,'value');
switch pnum
case 1
streetcar=imread('streetcar1.jpg');
case 2
streetcar=imread('streetcar2.jpg');
case 3
streetcar=imread('streetcar3.jpg');
otherwise
end
%---------streetcar=rgb2gray(streetcar);
c=streetcar;
%imshow(c);
b=imread('street.jpg');
%---------b=rgb2gray(b);
%figure;
%imshow(b);
%c=imsubtract(a,b);
%将待识别图像与背景图像进行比较,识别出车子,并只留下车子
for i=1:600
for j=1:800
if (abs(double(b(i,j,1))-double(streetcar(i,j,1)))>2)
c(i,j,1)=0;
c(i,j,2)=0;
c(i,j,3)=0;
elseif (abs(double(b(i,j,2))-double(streetcar(i,j,2)))>2)
c(i,j,1)=0;
c(i,j,2)=0;
c(i,j,3)=0;
elseif (abs(double(b(i,j,3))-double(streetcar(i,j,3)))>2)
c(i,j,1)=0;
c(i,j,2)=0;
c(i,j,3)=0;
else
c(i,j,1)=255;
c(i,j,2)=255;
c(i,j,3)=255;
end
end
end
%图像处理,包括灰度化,二值化和腐蚀,去除噪声
%c=imcomplement(c)
%c=immultiply(a,c);
c=rgb2gray(c);
leftcar=dither(c);
%figure;
%imshow(leftcar);
leftcar=~leftcar;
%figure;
%imshow(leftcar);
leftcar=bwmorph(leftcar,'erode',1);
leftcar=~leftcar;
%leftcar=bwmorph(leftcar,'erode',5);
leftcar=~leftcar;
vsumleftcar=sum(leftcar,2);
%找到车棚,并得到宽度
for i=1:599
if (vsumleftcar(i)<80) & (vsumleftcar(i+1)>80)
top=i;
break;
end
end
for i=1:599
if (vsumleftcar(600-i)<80) & (vsumleftcar(599-i)>80)
bottom=600-i;
break;
end
end
topvalue=vsumleftcar(bottom-ceil((bottom-top)*4/5));
bottomvalue=vsumleftcar(bottom-ceil((bottom-top)*2/5));
maxvalue=max(vsumleftcar);
percent=topvalue/maxvalue;
axes(handles.axes2);
imshow(~leftcar);
h=findobj(gcf,'Tag','text2');
%根据判断依据确定车型
if (percent>=0.2) & (percent<=0.5)
set(h,'String','小型车');
elseif (percent>0.5) & (percent<=0.8)
set(h,'String','中型车');
elseif percent>0.8
set(h,'String','大型车');
end
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
IT狂飙
- 粉丝: 4822
- 资源: 2654
最新资源
- zblog站群:zblog seo站群高收录排名全地域霸屏
- 【安卓毕业设计】数独联网对战APP源码(完整前后端+mysql+说明文档).zip
- 【安卓毕业设计】Android天气小作业源码(完整前后端+mysql+说明文档).zip
- 【安卓毕业设计】群养猪生长状态远程监测源码(完整前后端+mysql+说明文档).zip
- 【安卓毕业设计】奶牛管理新加功能源码(完整前后端+mysql+说明文档).zip
- C#.NET公墓陵园管理系统源码数据库 SQL2008源码类型 WebForm
- 作业这是作业文件这是作业
- 【物理化学实验报告】挥发性双液系气-液平衡相图的测绘.pdf
- 4353_135543959.html
- C#物联订单仓储综合管理系统源码 物联综合管理系统源码数据库 SQL2008源码类型 WebForm
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈