Effacer les filtres
Effacer les filtres

Using rectangle function in gui, not getting displayed?

2 vues (au cours des 30 derniers jours)
Avinash S
Avinash S le 7 Mar 2016
Commenté : Avinash S le 11 Mar 2016
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

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Mar 2016
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 commentaire
Avinash S
Avinash S le 11 Mar 2016
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

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by