MATLAB: Using rectangle function in gui, not getting displayed

axesguiImage Acquisition Toolboxlive videorectangle

I have created a gui to insert video stream from webcam based on the code from
I have previously used rectangle function in normal figures with imshow and hold on, to put bounding boxes to track human. Now I want to use the rectangle function in gui. I tried displaying in a small while loop for testing. But Im not getting it.
Code:
function myCameraGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.video = videoinput('winvideo', 2);
set(handles.video,'TimerPeriod', 0.05, ...
'TimerFcn',['if(~isempty(gco)),'...
'handles=guidata(gcf);'... % Update handles
'image(getsnapshot(handles.video));'... % Get picture using GETSNAPSHOT and put it into axes using IMAGE
'set(handles.cameraAxes,''ytick'',[],''xtick'',[]),'... % Remove tickmarks and labels that are inserted when using IMAGE
'else '...
'delete(imaqfind);'... % Clean up - delete any image acquisition objects
'end']);
triggerconfig(handles.video,'manual');
handles.video.FramesPerTrigger = Inf; % Capture frames until we manually stop it
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes mycameragui wait for user response (see UIRESUME)
uiwait(handles.myCameraGUI);
%------
%Callback Fn for startCamera Button
function startStopCamera_Callback(hObject, eventdata, handles)
if strcmp(get(handles.startStopCamera,'String'),'Start Camera')
% Camera is off. Change button string and start camera.
set(handles.startStopCamera,'String','Stop Camera')
start(handles.video)
i=1;
x3=500;
y3=300;
while(i<20)
rectangle('Position',[x3,y3,10,10],'EdgeColor','r','LineWidth',1);
i=i+1
end
else
% Camera is on. Stop camera and change button string.
set(handles.startStopCamera,'String','Start Camera')
stop(handles.video)
end

Best Answer

Where is your drawnow() ?
Why are you drawing 20 rectangles in the same position on the same frame?
Which figure or axes are you drawing the rectangles in?
Related Question