displaying compound images acquired from multiple cameras on 1 figure/GUI

Hi I am trying to preview a movie object that shows the difference image from 2 identical cameras. Eventually I want to create a GUI that shows either the sum image or the difference image. However, I can't seem to figure out if it's possible to create a video object from 2 video inputs. I tried using the setappdata command to create an UpdatePreviewWindowFcn that would take the difference between the 2 inputs, but the error message is not telling me what's wrong so I'm not sure how to fix. I am not sure if there is another way to modify the acquired data before previewing it other than updating the preview window function (via setappdata). Is there another way?
Alternatively, rather than previewing a video object I thought of reading the data and then just showing a movie. But here I am not sure how to order the commands such that each frame pair acquired by the 2 cameras becomes a frame in the movie that shows in real time.
Any tips on how to do this would be greatly appreciated. Please and Thank you. David

Answers (2)

2 Comments

Thank you, but the example you cite does not allow me to have live streaming of (img1 - img2). It does achieve blending of the images, but this was not my goal.
I've tried to rephrase my problem as such, using examples provided in the Matlab documentation. My code is adapted from the following example:
Image Acquisition Toolbox >> Image Preview and Device Configuration >> Previewing Data
Essentially, I created 2 video input objects, vid1 and vid2. These are identical webcams mounted on the end of a beam splitter. I want to PREVIEW the difference between the images in REAL TIME. The documentation suggested setting up the video objects and updating the preview color data using the setappdata function.
% create video objects for 2 cameras
vid1 = videoinput('winvideo', 1, 'MJPG_640x480');
src1 = getselectedsource(vid1);
vid2 = videoinput('winvideo', 2, 'MJPG_640x480');
src2 = getselectedsource(vid2);
start([vid1 vid2])
% Create an image object for previewing.
vidRes1 = get(vid1, 'VideoResolution');
nBands1 = get(vid1, 'NumberOfBands');
hImage = image( zeros(vidRes1(2), vidRes1(1), nBands1) );
setappdata(hImage,'UpdatePreviewWindowFcn',@difference_image);
preview(vid1, hImage);
My main problem is with the second to last command, setappdata, which, when used for previewing, does not pinpoint what my error was. It says in the documentation that a GUI event function callback implicitly passes the object and event as its input arguments. I want to add a second object and a second event as additional inputs, but this implicit argument passing becomes confusing and is not properly explained anywhere. Is it possible to have event callback functions that use 2 input objects? How should I structure the update function @difference_image? And how should I call it from my script?
Moreover, if you can explain to me what the proper syntax for passing additional arguments (unrelated to a second video input object) to this update function? Another functionality I want to add to the GUI is viewing the red, green, and blue channels individually as a BW image.
Thank you

Sign in to comment.

hi .. I want the code that take several snapshot using 2 cameras

Asked:

on 3 Mar 2013

Commented:

on 23 Jan 2018

Community Treasure Hunt

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

Start Hunting!