Overlay tracing with marker in MATLAB

4 views (last 30 days)
Clan
Clan on 7 Nov 2014
Commented: Dima Lisin on 11 Nov 2014
I am performing a tracking over RGB images. When i finish my tracking, i want to put a tracing over the image using the positions of the centroids calculated in each frame. Besides this tracing, I want to put a visual marker above each frame that represents where the movement is at each moment.
Imagine, in all frames you have the path with a different color, and above the path, in each frame, a moving marker will move around the path.
I've already performed this, but it takes too long. And consumes massive amount of RAM. Anyone can help me?
My try was:
markerInserter = vision.MarkerInserter('Shape','Circle','BorderColor','Custom','CustomBorderColor','red', ...
'Fill',1,'FillColor','Custom','CustomFillColor',[255 0 0],'Size',8,'Opacity',1);
z = waitbar(0,'Please wait...Tracking Labelling');
for i=1:length(ICollection)
frame_copia=ICollection{i,1};
h = figure(2);
set(h,'Visible','off');
frame = step(markerInserter, frame_copia,[int32(centroideccX(1,i)) int32(centroideccY(1,i))]);
imshow(frame); hold on
plot(centroideccX,centroideccY,'g','LineWidth',2.5)
frame = export_fig(h, '-nocrop', '-a1');
frame=imresize(frame, [480 640]);
Traced{i,1}=frame;
waitbar((i / length(ICollection)))
end
close(z)

Answers (1)

Dima Lisin
Dima Lisin on 10 Nov 2014
Hi Clan,
Your code takes too long and uses up a lot of memory, because you are overlaying the frames on top of one another in a single figure using hold on. Basically, all of your video frames stay in memory.
A better way would be not to use plot, but to draw the trace directly into the image using vision.ShapeInserter. Then you could simply save the frame into a file using imwrite.
Also, if you have a recent version of MATLAB, you could use insertMarker and insertShape functions instead of vision.MarkerInserter and vision.ShapeInserter respectively.
  2 Comments
Image Analyst
Image Analyst on 10 Nov 2014
Or, if you don't have the Computer Vision System Toolbox I think you can set the cdata property of the axes instead of using imshow(), or call "cla" before calling imshow(). But anyway, like Dima said, it's not plot() that is taking up all the time.
Dima Lisin
Dima Lisin on 11 Nov 2014
Hi Image Analyst,
vision.MarkerInserter is in the Computer Vision System Toolbox, so Clan definitely has it.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!