水果识别自助水果超市matlab源码含 GUI
Posted Matlab走起
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了水果识别自助水果超市matlab源码含 GUI相关的知识,希望对你有一定的参考价值。
一、简介
基于matlab自助水果超市
二、源代码
function varargout = rmbbb(varargin)
% RMBBB MATLAB code for rmbbb.fig
% RMBBB, by itself, creates a new RMBBB or raises the existing
% singleton*.
%
% H = RMBBB returns the handle to a new RMBBB or the handle to
% the existing singleton*.
%
% RMBBB('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RMBBB.M with the given input arguments.
%
% RMBBB('Property','Value',...) creates a new RMBBB or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before rmbbb_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to rmbbb_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 rmbbb
% Last Modified by GUIDE v2.5 11-Oct-2017 22:05:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @rmbbb_OpeningFcn, ...
'gui_OutputFcn', @rmbbb_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 rmbbb is made visible.
function rmbbb_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 rmbbb (see VARARGIN)
% Choose default command line output for rmbbb
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes rmbbb wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = rmbbb_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;
function pushbutton1_Callback(hObject, eventdata, handles)
% --- Executes on button press in pushbutton1.
% 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)
global image %定义一个全局变量im
[filename,pathname,filterindex]=uigetfile({'*.jpg';'*.png'},'选择图片')
str=[pathname filename]; %合成路径+文件名
image=imread(str); %读取图片
axes(handles.axes1); %使用第一个axes
imshow(image); %显示图片
RGB = image;
I = rgb2gray(RGB);
threshold = graythresh(I);
bw = im2bw(I,threshold);
% remove all object containing fewer than 30 pixels
bw = bwareaopen(bw,30);
% fill a gap in the pen's cap
se = strel('disk',2);
bw = imclose(bw,se);
% fill any holes, so that regionprops can be used to estimate
% the area enclosed by each of the boundaries
bw = imfill(bw,'holes');
ed=edge(bw);
%%%%%以上是图像二值化 上面制作二值化图像
%下面计算圆度
L = bwlabel(bw);
L1 = bwlabel(ed);
Ar=zeros(1,max(L(:)));
Pr=zeros(1,max(L1(:)));
for i=1:max(L(:))
Ar(i)=sum(bw(L==i));
[y,x]=find(L==i);
x0=min(x(:));
x1=max(x(:));
y0=min(y(:));
y1=max(y(:));
Pr(i)=Ar(i)/((y1-y0)*(x1-x0));
end
if max(Pr) >0.81
note=1
else
note=0
end
if note==1
imager=image(:,:,1);
imageg=image(:,:,2);
r=sum(sum(imager));
g=sum(sum(imageg));
bizhi=r/g;
if bizhi>1.15
money=100
elseif bizhi<0.93
money=50
elseif (bizhi>1.08)&(bizhi<1.15)
money=20
elseif (bizhi>1.0)&(bizhi<1.03)
money=10
elseif (bizhi>1.03)&(bizhi<1.08)
money=5
elseif (bizhi>0.93)&(bizhi<1.0)
money=1
end
end
if note==0
total= bwarea(bw)
if total>12000
money=1
elseif (total>10000)&(total<12000)
money=0.5
elseif (total>8700)&(total<10000)
money=0.1
else
money=0
end
end
global allmoney;
set(handles.edit1,'string',money);
allmoney=allmoney+money;
set(handles.edit8,'string',allmoney);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
allmoney=0;
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
三、运行结果
四、备注
完整代码或者代写添加QQ1575304183
以上是关于水果识别自助水果超市matlab源码含 GUI的主要内容,如果未能解决你的问题,请参考以下文章
水果识别基于matlab GUI灰度二值化草莓识别含Matlab源码 653期
水果识别基于matlab GUI形态学水果识别含Matlab源码 1364期