how to draw an updating rectangle object on a video stream ?

Hi there,
I am beginninger of matlab. I tried myCameraGUI example which build up a simple camera preview inferface. My question is I cannot find a way to draw a updating rectangle object on the top of streamed video. I do have tried many times, but fail in the end. Does anyone know how to do that? Any direction, webpage, or even a function would be appreciated. Thank you.
Steven

 Accepted Answer

It's possible to have graphics in the overlay above your live video. Did you call the preview() function to get live video, and then call plot() to plot your box?

3 Comments

No, I used start(handles.video) to play the view. and then I run this bit of code to initial and updating the mark
DELAY = 0.025;
numPoints = 600;
%# create data
x = linspace(0,10,numPoints);
y = log(x);
%# create moving point + coords text
hLine = line('XData',x(1), 'YData',y(1), 'Color','r', ...
'Marker','o', 'MarkerSize',6, 'LineWidth',2);
set(hLine,'Parent',handles.cameraAxes); % set ploting axes
%# infinite loop
i = 1; %# index
flag = 1;
while flag
%# update point & text
set(hLine, 'XData',x(i), 'YData',y(i))
drawnow %# force refresh
pause(DELAY) %# slow down animation
i = rem(i+1,numPoints)+1; %# circular increment
end
Matlab returns an error when executing set(hLine, 'XData',x(i), 'YData',y(i)). And I don't know what goes wrong
You need two x and two y, not one. Try calling line just like this
axes(handles.cameraAxes);
hold on;
line([x1 x2], [y1 y2]);
Could I ask you a question further? Say I'd like to process the input video frame by frame, and base on each frame that I get from the source camera I calculate the box and then update the box that I originally ploted on the video, what is best way of doing this in terms of system performance? Could you please recommand me a few functions that could do this. thanks a lot

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!