How to have different preview windows for a single video object?

1 次查看(过去 30 天)
I have a single video object from a webcam that I want to be previewed in two windows at the same time, how can I accomplish this?

采纳的回答

Siddharth Bhutiya
Siddharth Bhutiya 2018-8-17
When you preview the video from a "videoinput" object, MATLAB will continuously retrieve the image data from the webcam and display it on the screen. So, you will not be able to create another preview using the same videoinput object as that object will already be in use by the previous preview window.
However, in order to display two preview windows simultaneously you can try the following workaround and see if it fits your workflow.
vid = videoinput('winvideo',1);
figure;
im_handle1 = image(zeros(1280,720));
figure;
global im_handle2
im_handle2 = image(zeros(1280,720));
setappdata(im_handle1, 'UpdatePreviewWindowFcn',@my_callback_fcn);
preview(vid,im_handle1);
function my_callback_fcn(obj, event, himage)
global im_handle2
set(himage,'CData',event.Data);
set(im_handle2,'CData',event.Data);
end
The "UpdatePreviewWindowFcn" callback function will be executed every time a new frame is obtained from the webcam. So, we can create two image handles that will act as our preview windows and inside the callback function we update the "CData" for both the image handles, so that it displays the most recent frame. In this way you can display the same video on two different windows simultaneously.
Please note that if a frame is retrieved before the "UpdatePreviewWindowFcn" callback for the previous frame is completed, then that frame will be dropped.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by