Displaying multiple Targets in a same frame ( image)

4 views (last 30 days)
Hi all
I am working on multiple target tracking. I am able to track two objects but not able to display them in the same frame.
I am able to display the target in a same frame as two images. I want to display the two targets in the same image. Can you guys help me in this. I path I followed in the code is below. thank you
clear all;
close all;
clc;
[
get the video information
]
% for every frame in the video
for i = 1:maxFrame
% RGB frame
frame1 = mov(i).cdata;
% My frame
frame2 = frameRGB(:,:,3);
%I = frame2;
I = frameFS;
for j = 1:targets
if (i == 1)
%%%Detection mechanism
else
%%%detection mechanism
%%call function to draw detection window
Id = drawDetectionWindow(I, estPositionX(j), estPositionY(j), size);
% hold on ;
end
d = inf;
% Display the estimate position for every frame
fig4 = figure;
x2 = 2*positionOffset + videoWidth;
y2 = screenHeight - 2*videoHeight - 2*positionOffset;
set(fig4, 'Name', 'Estimated frame-by-frame', 'NumberTitle', 'off', 'Position', [x2 y2 videoWidth videoHeight])
image(Id);
%imshow(Id);
colormap(gray(256));
hold on
%avi = addframe(avi, Id);
filename = sprintf('ROI frames/frame%d_%d.jpeg', i,j);
imwrite(Id,filename);
end
end

Answers (1)

Walter Roberson
Walter Roberson on 12 Aug 2011
Build one figure and update it within the loop, instead of building one figure per iteration of the loop.
Your "hold on" has nothing to work on, since you do not create any more graphics in the loop before building the new figure.
You should, however, be taking more care with your axes:
fig4 = figure;
%now set the figure size
%then,
axes4 = axes('Parent',fig4);
%then, within the loop,
images(axes4, Id);
colormap(axes4, gray(256));
%and if necessary,
hold(axes4,'on');
  2 Comments
ram m
ram m on 12 Aug 2011
Thank you,
I was taking the fresh image every time instead of the modified image,
but I could not understand the axes problem you mentioned.
Walter Roberson
Walter Roberson on 12 Aug 2011
Refer to your previous code; you had
fig4 = figure;
and then you had
image(Id);
Now, how do you know *for sure* that the image will be displayed somewhere inside fig4 ?
_Normally_ when you use figure(), the figure so created becomes the "current figure" (gcf). And _Normally_ when you use a graphics command such as image() and there is no current axes set, the graphics routines will act on your behalf to automatically create an axes for you inside the current figure, as if by using
axes('Parent',gcf)
and making that the current axes, gca
then your plotting routine, not having been told which axes to plot in to, will use gca and plot in that axes.
Mostly that sequence works, but suppose that you had some call between the creation of the figure and the image() command. That call might happen to do some graphics activity (and there are some routines that need to create temporary figures that never show up on the screen), so in-between the figure() command and the image() command, MATLAB's idea of which figure gcf refers to might have changed, and your graphics might go to somewhere else completely, possibly in to a situation where it goes drawn so small that it is not noticed, or possibly in to a situation where it gets drawn off the screen... or possibly in to a situation where it scribbles over top of another plot you took a long time to calculate.
Therefore to be safe, it is better to always explicitly create the axes yourself and Parent it against the figure you want, and it is better to always explicitly draw your graphics items within the axes you know them to be destined for.
Suppose that between the time the figure was created and the time the image() was to be drawn, you (the user) happened to click on another figure, perhaps to minimize it or move it out of the way. Then in some circumstances the figure you clicked on might become the current figure, or if you had clicked within a plot then part of that plot might become the current axes, and again your image() might to elsewhere than where you expected. Unless, that is, you took precautions of saying explicitly where to draw it instead of relying upon the "current" figure or "current" axes not having changed.
One of the circumstances under which gcf or gca can change even if there are no calls that are allowed to change them, is if you have debugging on, and you have a breakpoint there (or single step). gcf and gca are updated at every breakpoint -- and of course breakpoints are often times when you want to grab a window and move it out of the way so you can see what is going on. Except doing so can make that window the current figure...
For your own self protection, always lock-down specifically which figure or axes or uipanel or whatever that you want to draw to. Always make sure that your uicontrol() and text() are parented against the right figure or uipanel or axes too, as the same problems can happen to them. These kinds of problems can be very mystifying and hard to reproduce, so get in the habit of writing your code to prevent them.
When your program gets even moderately complex, if you take the trouble to lock down all the figures and axes and so on, chances are you will find at least one bit of graphics that was not being put in the place it should be... graphics that might perhaps have been okay when it was first written but then code got moved around...

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!