フィルターのクリア

Using rectangle function in gui, not getting displayed?

2 ビュー (過去 30 日間)
Avinash S
Avinash S 2016 年 3 月 7 日
コメント済み: Avinash S 2016 年 3 月 11 日
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by