How can I plot line iteratively on an existing movie frame?
1 view (last 30 days)
Show older comments
Hi,
I want to visualize the trajectory of a moving ball in a movie. I obtain the centroid of the ball in each frame. I want to show a line path on the movie while the movie continues playing. Please suggest me a way to perform this?
My Code:
AviFrames; % This creates the movie as a struct in the workspace.
numF = evalin('base','numberOfFrames'); % Getting the number of frames in the movie
film = evalin('base','mov'); % Assigning the movie to "film" variable
initial_xy = [57.7411 35.5395]; % intitial cooridinates of the ball
p1b = [initial_xy(1,1),initial_xy(1,2)];
xs = zeros(numF, 2); % x coorinates of ball in the consecutive frames
ys = zeros(numF, 2); % y coorinates of ball in the consecutive frames
for i=1:numF
image = Struct2Image(i,film); % Converting struct to image (ith frame)
imshow(image);
[cx, cy, r] = CemberPoz(image); % Getting regionprops of the ball in the current image
cpos = [cx cy];
p2b = [cpos(1,1),cpos(1,2)];
pb = [p1b p2b];
bgx(i,:) = pb(1:2:3);
bgy(i,:) = pb(2:2:4);
p1b = p2b;
line([bgx(i,1) bgx(i,2)],[bgy(i,1) bgy(i,2)],'color','b','LineWidth',2);
hold on
axis([0 320 0 240])
hold off
end
Here is one screen capture:
Thanks in advance and kind regards, Tugrul Tasci
0 Comments
Answers (2)
Image Analyst
on 26 Aug 2012
Your screenshot didn't come through. And you need to not take hold off or else your first line will blow away all others.
1 Comment
Walter Roberson
on 26 Aug 2012
"hold" has no effect on line().
The poster is continually drawing new images and drawing new lines, so it is fine (other than from a performance point of view) to have the old contents continually blown away.
It is, however, not at all clear to me why the axis() command is there: in that context, it is going to create a new axis rather than resize the existing axis.
See Also
Categories
Find more on Animation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!