1
votes

My goal is to continuously plot the position & orientation of camera relative to marker using MATLAB.

There are three thing to plot.(1)camera (2)all circle points (3)origin point '*' Both the camera and points will be moving in each frame.I plotted all these three things in a static figure i.e. using hold on. as shown in the attached figure.

Now i want to plot them all continuously (real time) in the same figure as the values change.Till now i have only been able to dynamically update only one of these things i.e. the circular points for some random values. If I add another plot ,it conflicts.Can you please tell me how to update multiple plots in same figure and the plotCamera.

hF = figure;
hAx = gca;
im_pt_2world=rand(3,3);
x_o=im_pt_2world(1,1); y_o=im_pt_2world(1,2); %origin of the calibrated world points
x_ip=im_pt_2world(:,1); y_ip=im_pt_2world(:,2);

hpoints = plot3(x_ip, y_ip,zeros(size(im_pt_2world, 1),1),'ro');


% I added the "ishandle" so the program will end in case u closed the figure
while (1) & ishandle(hpoints)

   %instead of using plot I directly change the data in the line
   % this is faster the plot if only because you don't need to reedefine the limits and labels...
im_pt_2world=rand(3,3);
x_ip=im_pt_2world(:,1); y_ip=im_pt_2world(:,2);


   set(hpoints,'ydata',y_ip);
   set(hpoints,'xdata',x_ip);
   drawnow  %updates the display

end

1
Do you really need to solve such problem using set()? Can't you just overwrite the plot iself? This will be much easier, with no conflicts between the origin and the little circles. - AlessioX
@Alessiox overwriting the plot is much slower than updating the plot object's data. Especially noticeable with continuously updating graphics. - excaza
@excaza I agree with that, but my question is: should such plot really be that fast? It'll be like a storm of crazy circles raving around really fast. Is really a problem if such plot is a little bit slower? - AlessioX
@Alessiox since he wants it in real-time, obviously the answer is yes. - excaza
@excaza I guess you're right. I reckon the rand() is just for the sake of demo, given the attached picture. - AlessioX

1 Answers

1
votes

The plotCamera function (Computer Vision System Toolbox) returns a handle to the graphical object, which you can manipulate programmatically. Changing the object's properties, such as Location and Orientation will move the camera in the plot. The help example for plotCamera shows how to make the camera fly in a circle:

% Plot a camera pointing along the Y-axis
R = [1     0     0;
     0     0    -1;
     0     1     0];

% Setting opacity of the camera to zero for faster animation.
cam = plotCamera('Location', [10 0 20], 'Orientation', R, 'Opacity', 0);

% Set view properties
grid on
axis equal
axis manual

% Make the space large enough for the animation.
xlim([-15, 20]);
ylim([-15, 20]);
zlim([15, 25]);

% Make the camera fly in a circle
for theta = 0:pi/64:10*pi
    % Rotation about cameras y-axis
    T = [cos(theta)  0  sin(theta);
            0        1      0;
         -sin(theta) 0  cos(theta)];
    cam.Orientation = T * R;
    cam.Location = [10 * cos(theta), 10 * sin(theta), 20];
    drawnow();
end

If you really want to have fun with this, you can supply a function handle to be called when you click on the camera. For example, the function can display the image that the camera sees.