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 次查看(过去 30 天)
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 个评论
matt dash
matt dash 2014-12-13
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.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2014-12-13
编辑:Image Analyst 2014-12-13
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 个评论
HRISHIKESH
HRISHIKESH 2014-12-13
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 2014-12-13
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 :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by