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

2 vues (au cours des 30 derniers jours)
PaoloB
PaoloB le 11 Mar 2015
Commenté : Peer Blumido le 7 Juil 2017
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 commentaire
Amith Mudugamuwa
Amith Mudugamuwa le 4 Fév 2017
Hellow PaoloB,
I have the same problem. Could you find a way to get the video in GUI?
Thanks

Connectez-vous pour commenter.

Réponses (1)

Peer Blumido
Peer Blumido le 7 Juil 2017
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 commentaire
Peer Blumido
Peer Blumido le 7 Juil 2017
Instead of tab4 you have to write your figure. In my GUI i got an extra tab for the preview and capture the image.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by