More Examples: 3D-to-2D

advertisement

More Examples: 3D-to-2D

An object is viewed by a camera with image size

640x480, focal length = 500 pixels

The pose of the object (or model) with respect to the world is given by

H_m_w =

0.9254 0.0180 0.3785 0.5000

0.1632 0.8826 -0.4410 -0.5000

-0.3420 0.4698 0.8138 5.0000

0 0 0 1.0000

The orientation of the camera is aligned with the world

The origin of the camera is at world point = [0;0;-2]

Draw (in 3D) the coordinate axes of the world, the camera, and the model clear all close all

% good idea to do these at the beginning of each program

% XYZ coordinate axes (first column is the origin).

Paxes = ...

[0 1 0 0;

0 0 1 0;

0 0 0 1;

1 1 1 1];

% Draw a dot at the world origin. This also opens a new figure.

plot3(0,0,0, '.' ); hold on

1 of 2

% Draw axes for the world frame.

P_w = Paxes; line([P_w(1,1) P_w(1,2)], [P_w(2,1) P_w(2,2)], [P_w(3,1) P_w(3,2)], 'Color' , 'r' ); line([P_w(1,1) P_w(1,3)], [P_w(2,1) P_w(2,3)], [P_w(3,1) P_w(3,3)], 'Color' , 'g' ); line([P_w(1,1) P_w(1,4)], [P_w(2,1) P_w(2,4)], [P_w(3,1) P_w(3,4)], 'Color' , 'b' ); text(P_w(1,1),P_w(2,1),P_w(3,1), '{W}' );

% Camera pose.

H_c_w = ...

[ 1 0 0 0;

0 1 0 0;

0 0 1 -2;

0 0 0 1];

% Draw axes for the camera frame.

P_w = H_c_w * Paxes; line([P_w(1,1) P_w(1,2)], [P_w(2,1) P_w(2,2)], [P_w(3,1) P_w(3,2)], 'Color' , 'r' ); line([P_w(1,1) P_w(1,3)], [P_w(2,1) P_w(2,3)], [P_w(3,1) P_w(3,3)], 'Color' , 'g' ); line([P_w(1,1) P_w(1,4)], [P_w(2,1) P_w(2,4)], [P_w(3,1) P_w(3,4)], 'Color' , 'b' ); text(P_w(1,1),P_w(2,1),P_w(3,1), '{C}' );

% Model pose.

H_m_w = [

0.9254 0.0180 0.3785 0.5000;

0.1632 0.8826 -0.4410 -0.5000;

-0.3420 0.4698 0.8138 5.0000;

0 0 0 1.0000];

2 of 2

% Draw axes for the model frame.

P_w = H_m_w * Paxes; line([P_w(1,1) P_w(1,2)], [P_w(2,1) P_w(2,2)], [P_w(3,1) P_w(3,2)], 'Color' , 'r' ); line([P_w(1,1) P_w(1,3)], [P_w(2,1) P_w(2,3)], [P_w(3,1) P_w(3,3)], 'Color' , 'g' ); line([P_w(1,1) P_w(1,4)], [P_w(2,1) P_w(2,4)], [P_w(3,1) P_w(3,4)], 'Color' , 'b' ); text(P_w(1,1),P_w(2,1),P_w(3,1), '{M}' );

% These options make the 3D display look nicer.

axis equal axis vis3d

Draw Axes onto image

Create intrinsic camera matrix K

Create extrinsic matrix Mext, representing the pose of the model with respect to camera

Project the model points using p = K Mext P

Write the points into a blank image

Draw lines onto the image

Download