Plotting the preview from webcam in the matlab app window in real time.
조회 수: 36 (최근 30일)
이전 댓글 표시
I am developing an app which requires the real time video being captured from a webcam to be displayed. the preview function does this but it comes as a popup. I dont want a separat popup but i want this figure to appear in my matalb app window inside a panel/ uiaxes. Is it possibel to do so? the below figure shows the popup as "Figure 2" but i want this video to appear in the Panel6. Can someone please help me?
댓글 수: 0
답변 (1개)
Ayush Anand
2024년 5월 23일
편집: Ayush Anand
2024년 5월 23일
You can do this using the webcam support in MATLAB (https://in.mathworks.com/help/releases/R2023a/supportpkg/usbwebcams/ug/webcam.html). You can follow the steps below:
1. Install the support for USB Web cam in MATLAB using matlab.internal.addons.showAddon('USBWEBCAM'); command in the command window.
2.Add a "UIAxes" component to your app where the video will be displayed.
3.Since you need to continuously capture frames from the webcam and display them on the UIAxes, you can use a timer object that periodically fetches a frame from the webcam and displays it. Create properties for the webcam and timer in the "Properties" section of the code.
properties (Access = private)
cam % Webcam object
timer % Timer object
end
4.Initialize the webcam and timer in the `"startupFcn"
function startupFcn(app)
app.cam = webcam; % Initializes the webcam
app.timer = timer('ExecutionMode', 'fixedRate', 'Period', 0.1, 'TimerFcn', @(~,~)updateVideo(app));
start(app.timer);
end
5. Implement the "updateVideo" function to capture and display frames.
function updateVideo(app)
frame = snapshot(app.cam);
image(app.UIAxes, frame);
axis(app.UIAxes, 'image');
axis(app.UIAxes, 'off');
end
6. Cleanup in the "CloseRequestFcn" to stop the timer and release the webcam.
function CloseRequestFcn(app)
stop(app.timer);
delete(app.timer);
clear('app.cam');
delete(app);
end
댓글 수: 3
Ayush Anand
2024년 5월 24일
편집: Ayush Anand
2024년 5월 24일
This looks good! Now you just need to add a UI Axes component to your app from the design view:
And you can just run the app now. You should be able to see the webcam preview in the UI panel!
참고 항목
카테고리
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!