How to preview a webcam object in a figure (no preview window).

조회 수: 1 (최근 30일)
PaoloB
PaoloB 2015년 3월 11일
댓글: Peer Blumido 2017년 7월 7일
I am a little confused about the two different video objects that Matlab uses. On one hand one can create an image acquisition object and then preview it using
preview(obj)
which creates a preview window, or
preview(obj,himage)
which will display the preview in an image (for instance if you want to have the preview in your gui).
Then there are the "webcam" objects, which only allows to open the preview in a preview windows. I have tried to use the second format (obj, himage) with a webcam object and it works but the problem arises when you try to stop the stream (closePreview), as this will also destroy/close the container, and crash Matlab.
So my question: is there a way to have the webcam preview in a GUI?
Please also note that if I try to list the video objects in Matlab the webcam does not appear (it appears with webcamlist though).
Attached is a snippet of code that produces horrible consequences on Matlab (need to kill the process).
  댓글 수: 1
Amith Mudugamuwa
Amith Mudugamuwa 2017년 2월 4일
Hellow PaoloB,
I have the same problem. Could you find a way to get the video in GUI?
Thanks

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

답변 (1개)

Peer Blumido
Peer Blumido 2017년 7월 7일
Hi, if you mean to show your preview in a window inside your GUI figure. I used this. BildCamaxes is for you preview size in your figure.
BildCamaxes = axes(tab4,'Units','pixels','Position',[240,20,520,330]); vid = videoinput('winvideo',2); vidRes = vid.VideoResolution; nBands = vid.NumberOfBands; hImage = image(zeros(vidRes(2),vidRes(1), nBands),'Parent',BildCamaxes); preview(vid, hImage);
  댓글 수: 1
Peer Blumido
Peer Blumido 2017년 7월 7일
Instead of tab4 you have to write your figure. In my GUI i got an extra tab for the preview and capture the image.

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

Community Treasure Hunt

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

Start Hunting!

Translated by