필터 지우기
필터 지우기

Plotting the preview from webcam in the matlab app window in real time.

조회 수: 10 (최근 30일)
Ron
Ron 2024년 5월 23일
댓글: Ron 2024년 5월 25일
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?

답변 (1개)

Ayush Anand
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
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!
Ron
Ron 2024년 5월 25일
Thankyou for your quick response. I did the same but the preview is not there. This is what I am getting.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by