Im making a gui for motion detection program .This is where im finding difficulty.I want display the result in edit box of gui but im getting an error "Error while evaluating uicontrol Callback". Can anyone tell me how to solve it ? ?

1 view (last 30 days)
function untitled13_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = untitled13_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
vid = videoinput('winvideo', '2','YUY2_640x480');
set(vid, 'ReturnedColorSpace', 'RGB');
start(vid)
preview(vid)
img = getsnapshot(vid);
pause(2)
img1 = getsnapshot(vid);
img12 = rgb2gray(img1);
img13 = rgb2gray(img);
dif =sum(sum(img12 - img13));
disp (dif)
set(handles.edit1,'string',num2str(dif));
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
when i run this i get an error Error while evaluating uicontrol Callback
  1 Comment
matt dash
matt dash on 13 Dec 2014
When you need help with an error, post the entire red error message, which explains where in your code the error occurs. This helps readers more easily identify what went wrong.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 13 Dec 2014
Edited: Image Analyst on 13 Dec 2014
Well like Matt says, it's not clear because you didn't include the entire error message. But I can see some things wrong right off the bat. You're not subtracting correctly. The images need to be converted to double or you'll only find pixels where img12 is brighter than img13.
%dif =sum(sum(img12 - img13)); % NO!
%disp (dif) % Also No. Don't print to the command line!
meanDifferenceImage = abs(double(img12) - double(img13));
meanDifference = mean(meanDifference(:))
str = sprintf('The mean difference = %.2f gray levels.', meanDifference);
set(handles.edit1,'string', str);
Also, read this please and fix your post's formatting.
  6 Comments
HRISHIKESH
HRISHIKESH on 13 Dec 2014
OMGGG .thanksss a lot man.it worked.Really appreciate this.Such a simple mistake and i spent around 6 hours trying to fix it. Again tahnks a looooot :)))))
HRISHIKESH
HRISHIKESH on 13 Dec 2014
Finalyy i can finish my project thanks to you :).This also solved another query of mine (that if i can dynamically update edit box).Seems i didnt have to do any thing special for it .Youre lifesaver :)

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!