How to draw a circle on moving video on matlab?

I would like to figure a circle on moving image by using a usb-camera. My simply-made code goes like this.
clc;
clear all;
vid=videoinput('winvideo',1,'YUY2_160x120');
preview(vid);
vid.ReturnedColorSpace='rgb';
for t=0:2*pi/400:2*pi
x=round(10*cos(t)+50);
y=round(15*sin(t)+50);
xx=round(10*cos(t)+50);
yy=round(15*sin(t)+110);
xxx=round(20*cos(t)+60);
yyy=round(15*sin(t)+80);
vid(x,y,1)=200;
vid(xx,yy,2)=200;
vid(xxx,yyy,3)=200;
end
imshow(vid);
but the error message says 'Video input objects can only be concatenated with other video input objects.'. how can I handle this thing?

Answers (1)

Plot it in the overlay with plot(). See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F

4 Comments

It seems like you are explaining about drawing a circle on 'image'. Does it also apply for video with the same way? I meant to draw a circle on 'video' itself, not after taking snapshot form USB-camera.
I have stuff in the overlay above live video all the time. Like a circle in red and the live video moving underneath it. Is that what you're wanting to do? Or do you want to capture video and actually "burn" the circle into the pixels of each frame? Where each frame actually has pixels in a circle that are pure red and not the video colors they started out with?
Yes that's what I exactly want to do. A circle in certain color and size live video moving underneath it ! how can I implement that function? As you can see above, I just tried to make three different circles with the base of 'vid' which is videoinput and use 'imshow' to figure but it didn't work at all.
You can't use imshow() because that will put an opaque image in the buffer, essentially covering up your live video. You need to use computer graphics. See the FAQ for how to create a N by 2 list of (x,y) coordinates, and then use plot(x, y, 'r-') to plot those coordinates over the live video.

Sign in to comment.

Tags

Asked:

seo
on 28 May 2013

Community Treasure Hunt

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

Start Hunting!