# API Reference¶

class pymvg.camera_model.CameraModel(name, width, height, _rquat, _camcenter, P, K, distortion, rect)[source]

an implementation of the Camera Model used by ROS and OpenCV

Tranformations: We can think about the overall projection to 2D in two steps. Step 1 takes 3D world coordinates and, with a simple matrix multiplication and perspective division, projects them to undistorted 2D coordinates. Step 2 takes these undistorted 2D coordinates and distorts them so they are ‘distorted’ and match up with a real camera with radial distortion, for example.

3D world –(step1)—-> undistorted 2D —(step2)—-> distorted 2D

Step 1 is accomplished by making the world coordinates a homogeneous vector of length 4, multiplying by a 3x4 matrix M (built from P, R and t) to get values [r,s,t] in which the undistorted 2D coordinates are [r/t, s/t]. (The implementation is vectorized so that in fact many points at once can be transformed.)

Step 2 is somewhat complicated in that it allows a separate focal length and camera center to be used for distortion. Undistorted 2D coordinates are transformed first to uncorrected normalized image coordinates using parameters from P, then corrected using a rectification matrix. These corrected normalized image coordinates are then used in conjunction with the distortion model to create distorted normalized pixels which are finally transformed to distorted image pixels by K.

Coordinate system: the camera is looking at +Z, with +X rightward and +Y down. For more information, see http://www.ros.org/wiki/image_pipeline/CameraInfo

As noted on the link above, this differs from the coordinate system of Harley and Zisserman, which has Z forward, Y up, and X to the left (looking towards +Z).’

camcenter_like(nparr)[source]

create numpy array of camcenters like another array

get_aligned_camera(scale, rotation, translation)[source]

return a copy of this camera with new extrinsic coordinates

get_flipped_camera()[source]

return a copy of this camera looking in the opposite direction

The returned camera has the same 3D->2D projection. (The 2D->3D projection results in a vector in the opposite direction.)

get_mirror_camera(axis='lr', hold_center=False)[source]

return a copy of this camera whose x coordinate is (image_width-x)

axis - string. Specifies the axis of the mirroring, either ‘lr’ or ‘ud’. hold_center - boolean. Preserve the optical center?

get_view_camera(eye, lookat, up=None)[source]

return a copy of this camera with new extrinsic coordinates

is_distorted_and_skewed(max_skew_ratio=1000000000000000.0)[source]

True if pixels are skewed and distorted

is_opencv_compatible()[source]

True iff there is no skew

is_skewed(max_skew_ratio=1000000000000000.0)[source]

True if pixels are skewed

classmethod load_camera_from_M(pmat, width=None, height=None, name='cam', distortion_coefficients=None, _depth=0, eps=1e-15)[source]

create CameraModel instance from a camera matrix M

classmethod load_camera_from_opened_bagfile(bag, extrinsics_required=True)[source]

factory function for class CameraModel

bag - an opened rosbag.Bag instance extrinsics_required - are extrinsic parameters required

project_3d_to_camera_frame(pts3d)[source]

take 3D coordinates in world frame and convert to camera frame

project_camera_frame_to_3d(pts3d)[source]

take 3D coordinates in camera frame and convert to world frame

save_to_bagfile(fname, roslib)[source]

save CameraModel to ROS bag file

fname - filename or file descriptor to save to roslib - the roslib module

class pymvg.multi_camera_system.MultiCameraSystem(cameras)[source]
find3d(pts, undistort=True)[source]

Find 3D coordinate using all data given

Implements a linear triangulation method to find a 3D point. For example, see Hartley & Zisserman section 12.2 (p.312).

By default, this function will undistort 2D points before finding a 3D point.

classmethod from_mcsc(dirname)[source]

create MultiCameraSystem from output directory of MultiCamSelfCal

get_aligned_copy(other)[source]

return copy of self that is scaled, translated, and rotated to best match other