How to preview a webcam object in a figure (no preview window).
2 views (last 30 days)
Show older comments
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 Comment
Amith Mudugamuwa
on 4 Feb 2017
Hellow PaoloB,
I have the same problem. Could you find a way to get the video in GUI?
Thanks
Answers (1)
Peer Blumido
on 7 Jul 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 Comment
Peer Blumido
on 7 Jul 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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!