How to prevent overwriting of the frames in preview output window

I am coding a program to * acquire frames from the webcam ==> draw a bounding box using a custom UpdatePreviewWindowFcn==> update the CData of an image object(himage) and display it using the preview(vidobj,himage) function.*
The program works correctly without any error but the problem is, it displays the frames one over the other in the figure window.
i.e.. The boundingbox which was drawn on the previous frame, continues to be shown on the next frames also.
1. How do i clear the figure window each time before displaying the frame (in himage) or tell me other way so that only the boundingbox of the current frame is visible
2. When I'm using preview(videoobj,himage) , the output is displayed in a figure window and it is not maximized, it is displayed in a smaller window even if i use the resolution as 1024x768. (himage is init to be zeros(768,1024,3) )
3. & I'm not clear with CData of an image. Please explain me about this and please help me understand the following
I'm using a custom function for UpdatePreviewWindowFcn.
i. Why to use preview(videoobject,himage)? i didn't understand this " displays live video data for video input object obj in the image object specified by the handle himage." well.
What is the advantage of using an image object and displaying it's data over using the "handle to the image object that is being updated" which is passed as the third parameter to my custom fuction .

1 Comment

Hello?!!! i have been waiting long for an answer..
Please help....

Sign in to comment.

Answers (1)

1. See the documentation for clf, cla, and delete(). Also consider the possibility of not drawing a new bounding box each time and instead update the previous bounding box to the new size and position.

4 Comments

I tried using clf but it didn't solve the problem..
And can you explain how we can "update the previous BoundingBox to the new sizw and position" ?. I am actually processing the acquired frame and finding a specific object, say a red colored object, and drawing a rectangle, whose position is given by the BoundingBox region property. If the object moves to a different location in the next frame, how to update the rectangle?
rh = rectangle(....);
then later
set(rh, 'Position', NewPosition)
See http://www.mathworks.com/help/techdoc/ref/rectangle_props.html
Thank you Mr. Roberson !
I worked on your suggestion and Solved my problem 1!
Though, only updating the rectangle's postition didn't seem to solve the problem.
it works for me when i use :
----------------------------------------------------
rh=rectangle(...)
set(rh,'EraseMode','xor');
set(rh,'Position',...) %updating
-----------------------------------------------------------
Even if i change the erasemode to 'normal' or 'background' it wasn't working 4 me.
Thx..
Now waiting for answers to my other questions......
CData of an image object is the property of the object that stores the pixel values. set() new values for the CData property and arrange to have the display updated and the image on the screen will change. This is documented in the "image properties" documentation.

Sign in to comment.

Asked:

on 3 Jun 2011

Community Treasure Hunt

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

Start Hunting!