Using rectangle function in gui, not getting displayed?

2 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2016-3-7
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?
  1 个评论
Avinash S
Avinash S 2016-3-11
drawnow was the cause. thank you @Walter Robertson. I just wanted to check thats why i<20. And its not the same frame, It displays frames streaming from webcam

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for IP Cameras 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by