user1471216
user1471216

Reputation: 43

Import picture of an object for plotting purposes?

I'm writing a program to simulate the movement of a chaser following a target. The chaser is supposed to have a camera, and based on the target image, it follows the target.

Now, I've used 4 planar points in a square shape to represent the camera of the chaser. Thus, for chasing, I'm updating the position of these 4 points in a 3D plot to represent chaser movement.

I would like to know if it's possible to import a picture of, say, an actual camera and use that instead of the present 4 points, for aesthetic purposes? If yes, how?

I'm not very familiar with MATLAB, so I'd appreciate it if you could be detailed and specific with your answer. Thanks in advance

Upvotes: 1

Views: 435

Answers (1)

Amro
Amro

Reputation: 124563

Here is a quick example (based on this):

%# grayscale image
img = imread('cameraman.tif');

%# x/y/z coords of image corners
[X,Z,Y] = meshgrid([-1 1],[1 -1],0);

%# plot image in 3D space
figure, colormap gray
h = surf(X,Y,Z,img, 'CDataMapping','scaled', ...
    'FaceColor','texturemap', 'EdgeColor','none');
set(gca, 'XLim',[-2 2], 'YLim',[-4 0], 'ZLim',[-2 2], 'Box','on')

%# move image along the Y-dimension
t = linspace(0,-4,20);
for i=1:numel(t)
    set(h, 'YData',t(i)*ones(size(Y)))
    pause(.1)
end

I created an animation of the result, I even used a camera image :)

animation

Upvotes: 3

Related Questions