资讯详情 【图像识别】基于形态学算法实现自助水果超市系统matlab代码
📅 2026/10/30 6:07:23
1 简介基于形态学算法实现自助水果超市系统matlab代码2 部分代码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 GUIDEs 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 EDITgui_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});endif nargout[varargout{1:nargout}] gui_mainfcn(gui_State, varargin{:});elsegui_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 rmbbbhandles.output hObject;% Update handles structureguidata(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 structurevarargout{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]; %合成路径文件名imageimread(str); %读取图片axes(handles.axes1); %使用第一个axesimshow(image); %显示图片RGB image;I rgb2gray(RGB);threshold graythresh(I);bw im2bw(I,threshold);% remove all object containing fewer than 30 pixelsbw bwareaopen(bw,30);% fill a gap in the pens capse 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 boundariesbw imfill(bw,holes);ededge(bw);%%%%%以上是图像二值化 上面制作二值化图像%下面计算圆度L bwlabel(bw);L1 bwlabel(ed);Arzeros(1,max(L(:)));Przeros(1,max(L1(:)));for i1:max(L(:))Ar(i)sum(bw(Li));[y,x]find(Li);x0min(x(:));x1max(x(:));y0min(y(:));y1max(y(:));Pr(i)Ar(i)/((y1-y0)*(x1-x0));endif max(Pr) 0.81note1elsenote0endif note1imagerimage(:,:,1);imagegimage(:,:,2);rsum(sum(imager));gsum(sum(imageg));bizhir/g;if bizhi1.15money100elseif bizhi0.93money50elseif (bizhi1.08)(bizhi1.15)money20elseif (bizhi1.0)(bizhi1.03)money10elseif (bizhi1.03)(bizhi1.08)money5elseif (bizhi0.93)(bizhi1.0)money1endendif note0total bwarea(bw)if total12000money1elseif (total10000)(total12000)money0.5elseif (total8700)(total10000)money0.1elsemoney0endendglobal allmoney;set(handles.edit1,string,money);allmoneyallmoneymoney;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);endallmoney0;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% --- 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)function edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (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 edit4 as text% str2double(get(hObject,String)) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (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);endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (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 edit5 as text% str2double(get(hObject,String)) returns contents of edit5 as a double% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (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);endfunction edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (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 edit6 as text% str2double(get(hObject,String)) returns contents of edit6 as a doubleendendendendset(handles.edit4,string,R);set(handles.edit5,string,p);% hObject handle to pushbutton4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton5.function pushbutton5_Callback(hObject, eventdata, handles)m str2num(get(handles.edit6,string));p str2num(get(handles.edit5,string));global qqm*p;set(handles.edit7,string,q);% hObject handle to pushbutton5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)function edit8_Callback(hObject, eventdata, handles)% hObject handle to edit8 (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 edit8 as text% str2double(get(hObject,String)) returns contents of edit8 as a double% --- Executes during object creation, after setting all properties.function edit8_CreateFcn(hObject, eventdata, handles)% hObject handle to edit8 (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% --- Executes on button press in pushbutton6.function pushbutton6_Callback(hObject, eventdata, handles)%pay str2num(get(handles.edit7,string));global qpayq;global allmoneyif (allmoneypay)Buttonquestdlg(您支付的金额不足,提示,继续支付,取消支付,继续支付);switch Buttoncase 取消支付helpdlg(交易失败,提示)allmoney0;endelsecashallmoney-pay;set(handles.edit3,string,cash);helpdlg(欢迎下次光临,交易成功)allmoney0;end% hObject handle to pushbutton6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% --- Executes on button press in pushbutton7.function pushbutton7_Callback(hObject, eventdata, handles)imimread(kongbai.jpg);axes(handles.axes1); %使用第一个axesimshow(im);axes(handles.axes2); %使用第一个axesimshow(im);set(handles.edit1,string,);set(handles.edit3,string,);set(handles.edit4,string,);set(handles.edit5,string,);set(handles.edit6,string,);set(handles.edit7,string,);set(handles.edit8,string,);allmoney0;% hObject handle to pushbutton7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)3 仿真结果