Info

此问题已关闭。 请重新打开它进行编辑或回答。

can anyone explain the code below/

2 次查看(过去 30 天)
Adnan Saify
Adnan Saify 2015-12-31
actually i am doing a project on traffic control system using image processing and i had got a code but i am unable to understand it as i dont have knowledge of handles and callback.so please help me out.Also i a getting thhe errorswhen i am executing the code.
function varargout = test1(varargin) % TEST1 M-file for test1.fig % TEST1, by itself, creates a new TEST1 or raises the existing % singleton*. % % H = TEST1 returns the handle to a new TEST1 or the handle to % the existing singleton*. % % TEST1('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TEST1.M with the given input arguments. % % TEST1('Property','Value',...) creates a new TEST1 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before test1_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to test1_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 test1
% Last Modified by GUIDE v2.5 30-Dec-2015 17:09:17
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @test1_OpeningFcn, ... 'gui_OutputFcn', @test1_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 test1 is made visible. function test1_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 test1 (see VARARGIN)
% Choose default command line output for test1 handles.pic='reference.png'; handles.output = hObject; handles.pic='real time.png'; % Update handles structure guidata(hObject, handles);
% UIWAIT makes test1 wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = test1_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)
%set(handles.text1, 'String', 'push button pushed') display('Initiating matching...'); display('Calibrating procedures...'); display('... ... ...'); k=handles.pic; p=handles.pic; [x,y,z] = size(k); if(z==1) ; else k = rgb2gray(k); end [x,y,z] = size(p); if(z==1) else p = rgb2gray(p); end %applying edge detection on first picture %so that we obtain white and black points and edges of the objects present %in the picture. k1=imresize(k,[300 300]); edge_det_k = edge(k1,'sobel'); %%applying edge detection on second picture %so that we obtain white and black points and edges of the objects present %in the picture. p1=imresize(p,[300 300]); edge_det_p = edge(p1,'sobel'); %definition of different variables to be used in the code below %output variable if pictures have been matched. OUTPUT_MESSAGE = ' RED for 90 seconds '; OUTPUT_MESSAGE2 = ' GREEN for 20 seconds '; OUTPUT_MESSAGE3 = ' GREEN for 30 seconds '; OUTPUT_MESSAGE4 = ' GREEN for 60 seconds '; OUTPUT_MESSAGE5 = ' GREEN for 90 seconds '; %initialization of different variables used
matched_data = 0; white_points = 0; black_points = 0; x=0; y=0; l=0; m=0; %for loop used for detecting black and white points in the picture. for a = 1:1:300 for b = 1:1:300 if(edge_det_k(a,b)==1) white_points = white_points+1; else black_points = black_points+1; end end end display('matching...'); %for loop comparing the white (edge points) in the two pictures for i = 1:1:300 for j = 1:1:300 if(edge_det_k(i,j)==1)&(edge_det_p(i,j)==1) matched_data = matched_data+1; else ; end end end
%calculating percentage matching. total_data = white_points; total_matched_percentage = (matched_data/total_data)*100; %handles.pp=total_matched_percentage; %guidata(hObject,handles); set(handles.result,'String',total_matched_percentage); %outputting the result of the system. if total_matched_percentage > 90 %can add flexability at this point by reducing the amount of matching. total_matched_percentage OUTPUT_MESSAGE display(OUTPUT_MESSAGE); set(handles.result1,'String',OUTPUT_MESSAGE); elseif total_matched_percentage <= 90 & total_matched_percentage > 70 total_matched_percentage OUTPUT_MESSAGE2 display(OUTPUT_MESSAGE2); set(handles.result1,'String',OUTPUT_MESSAGE2); elseif total_matched_percentage <= 70 & total_matched_percentage > 50 total_matched_percentage OUTPUT_MESSAGE3 display(OUTPUT_MESSAGE3); set(handles.result1,'String',OUTPUT_MESSAGE3); elseif total_matched_percentage <= 50 & total_matched_percentage > 10 total_matched_percentage OUTPUT_MESSAGE4 display(OUTPUT_MESSAGE4); set(handles.result1,'String',OUTPUT_MESSAGE4);
else total_matched_percentage OUTPUT_MESSAGE5 display(OUTPUT_MESSAGE5); set(handles.result1,'String',OUTPUT_MESSAGE5); end % --- Executes during object creation, after setting all properties.
function text1_CreateFcn(hObject, eventdata, handles) % hObject handle to text1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % -------------------------------------------------------------------- function source_Callback(hObject, eventdata, handles) % hObject handle to source (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) file = uigetfile('reference.png'); if ~isequal(file, 0) k=imread(file); handles.YY = k; z=k; guidata(hObject,handles); %guidata(hObject,handles); subplot(2,2,1),imshow(k);title('Reference Image'); end % -------------------------------------------------------------------- function new_Callback(hObject, eventdata, handles) % hObject handle to new (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function target_Callback(hObject, eventdata, handles) % hObject handle to target (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) file = uigetfile('real time.png'); if ~isequal(file, 0) p=imread(file); subplot(2,2,2),imshow(p);title('Captured Image'); handles.XX = p; guidata(hObject,handles); end % -------------------------------------------------------------------- function Untitled_2_Callback(hObject, eventdata, handles) % hObject handle to Untitled_2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function about_Callback(hObject, eventdata, handles) % hObject handle to about (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('This script file is a part of our project Image Processing based Intelligent Traffic Control Systems (IPITCS) and has been developed by Amber Deep Singh, Abdul Hadi Parwana and Kamran Shahid Baig under the able guidance of Mrs. Farida Khurshid, Department of Electronics and Communication, National Institue of Technology Srinagar.'); % -------------------------------------------------------------------- function Untitled_5_Callback(hObject, eventdata, handles) % hObject handle to Untitled_5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_6_Callback(hObject, eventdata, handles) % hObject handle to Untitled_6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function howto_Callback(hObject, eventdata, handles) % hObject handle to howto (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB NATIONAL INSTITUTE OF TECHNOLOGY SRINAGAR % handles structure with handles and user data (see GUIDATA) msgbox('Use images resized to 300*300 pixels'); % --- Executes during object creation, after setting all properties. function figure1_CreateFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called function open_Callback(hObject, eventdata, handles) % hObject handle to open (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) file = uigetfile('reference.jpg'); if ~isequal(file, 0) imshow(file); %open(source); end function result_Callback(hObject, eventdata, handles) % hObject handle to result (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 result as text % str2double(get(hObject,'String')) returns contents of result as a double % --- Executes during object creation, after setting all properties. function result_CreateFcn(hObject, eventdata, handles) % hObject handle to result (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) % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function result1_Callback(hObject, eventdata, handles) % hObject handle to result1 (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 result1 as text % str2double(get(hObject,'String')) returns contents of result1 as a double % --- Executes during object creation, after setting all properties. function result1_CreateFcn(hObject, eventdata, handles) % hObject handle to result1 (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 % -------------------------------------------------------------------- function help_Callback(hObject, eventdata, handles) % hObject handle to help (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes when figure1 is resized. function figure1_ResizeFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes when user attempts to close figure1. function figure1_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to figure1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: delete(hObject) closes the figure delete(hObject);
errors : ??? Error using ==> imresize>parsePreMethodArgs at 333 Invalid input syntax; input image missing from argument list.
Error in ==> imresize>parseInputs at 257 [params.A, params.map, params.scale, params.output_size] = ...
Error in ==> imresize at 141 params = parseInputs(varargin{:});
Error in ==> test1>pushbutton1_Callback at 103 k1=imresize(k,[300 300]);
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> test1 at 42 gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)test1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
  1 个评论
John D'Errico
John D'Errico 2015-12-31
We can have no idea what you did to create this error, what you have done. Nor is Answers the place for an in-depth explanation of handles, callbacks, and everything you might possibly need to know to use some code you got from somebody else.

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by