Trying to get snapshots of webcam to show up within GUI using App Designer
조회 수: 10 (최근 30일)
이전 댓글 표시
Says it all on the tin. I have my code running on a timer that reiterates every half a second or so, and in the function that gets reiterated, I want to have a webcam snapshot be visible within the app I'm making. I don't want the image to appear in a separate window. How would I do this?
댓글 수: 0
답변 (1개)
Rishabh Singh
2022년 1월 9일
Hey,
You can refer to "timer" for executing a scheduled command and to this documentation to refer to how to create a callback function.
Below is the callback function to load image from your webcam whenever it is called,
properties (Access = private)
Property % Description
cam = webcam("USB Video Device");
end
methods (Access = private)
function loadImage(app, obj, event, string_arg)
img = app.cam.snapshot();
app.Image.ImageSource = img;
disp('run');
end
end
% Callbacks that handle component events
methods (Access = private)
% Image clicked function: Image
function ImageClicked(app, event)
t = timer('StartDelay' , 1, 'Period', 0.5, 'ExecutionMode', 'fixedRate');
t.TimerFcn = @(obj, event)loadImage(app);
start(t);
end
end
You can call the above function using any of the callback function suitable to your specific need, here I have used "ImageClicked" callback to activate the timer function.
Hope this helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Acquisition Support Packages for Hardware Adaptors (Generic Video Interface)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!