next up previous contents
Next: Parallel Stereo Camera Geometry Up: Camera Geometry Previous: Introduction   Contents

Describing Cameras

In Tina cameras are represented by the following structure

typedef struct camera
      Ts_id   ts_id;            /* Tina structure identifier */
      /** camera info **/
      unsigned int type;
      unsigned int label;

      /** physical parameters **/
      float   f;                /* focal length */
      float   pixel;            /* notional pixel size */
      float   ax, ay;           /* x and y expansion factors (aspect ratio ) */
      float   cx, cy;           /* x and y image centre coordinates */
      int     width, height;    /* image height and width for which relevant */

      /** transformation from world to camera frame **/
      Transform3 *transf;

      /** optical distortion **/
      void   *distort_params;
      void   *(*copy_dist_func) ();
      Vec2 (*distort_func) ();
      Vec2 (*correct_func) ();

      /** projection from unit camera to image coordinates **/
      Mat3    cam_to_im;
      /** projection from image to unit camera coordinates **/
      Mat3    im_to_cam;

The type and label fields allow the system/user to keep a track on arbitary numbers of cameras.

A number of physical parameters are given. These describe a simple imaging model based on a pinhole camera. Some are image size dependent, and hence width and height fields are included to keep track on the size of image for which the camera definition is valid. For generality two expansion factors (with respect to the given pixel size) ax and ay are used to define the aspect ratio of the camera. For CCD arrays it is possible to fix at least one of these scale factors, to unity (as it is the same in all cameras of that type). Usually ay will be 1.0 as the spacing between scan lines is fixed.

The focal length f (if known or recoverable by calibration) is in the standard units of the Tina system (usually millimeters). Image centers (cx, cy) are in pixels and scale with the width and height of the image.

If available the transf field is used to store a pointer to a Transform3 which represents the transformation that takes points in a world coordinate frame into the coordinate frame of the physical camera. That is, at the optic center, with z along the principle axis and x and y parallel to the imaging plane; x along the image horizontal (+ve right) and y vertical (+ve down).

The two Mat3 fields cam_to_im and im_to_cam describe projective mappings between iconic image coordinates (measurements in pixels, origin at the top left of the image, etc) and camera image coordinates (metric units, origin at the center, x axis horizontal +ve to the right, y axis vertical +ve down, etc). That is

q' = Pq

where q and q' are 3 vectors representing points in each image coordinate frame and P is the projective mapping. Note that the 3 vector q = (x, y, w) represents the 2 vector image coordinate (x/w, y/w). The projection matrix cam_to_im takes camera image coordinates to their standard counterparts and im_to_cam the reverse. Each is derived, to some extent, from the physical parameters described above, and are dependent upon the height and with of the image (hence must be recomputed if the size of the image is changed).

The above mappings are able to remove known projective distortions of the image. Additionally, optional distortion and correction functions are supplied to deal with non projective distortions, these are distort_func and correct_func respectively. The field distort_params is available to store information required by these distortion functions. The standard form of one of these functions is

Vec2    cam_distort(Vec2 w, double *a)

Distortions/corrections take place in camera image coordinates and not standard image coordinates. Hence in order to obtain corrected standard image coords points must first be projected using im_to_cam, the correction applied using correct_func, and reprojected using cam_to_im.

This camera arrangement allows considerable leeway as to the actual representation of data. For instance, the projection plane of the camera image is not defined. Two obvious candidate locations exist, that is either at unity or at the focal length of the camera. For reasons of uniformity, we have adopted the former (unity) in the projection functions used in Tina.

By way of an example the sequence to of operations to project a point v in word coordinate frames to the point w in the standard iconic image frame is as follows

    Vec3 v;
    Vec2 w;
    Vec2 rectify_pos();

    /** transform into camera frame **/
    if (cam->transf != NULL)
        v = trans3_pos(*cam->transf, v);

    /** project onto unit focal plane **/
    w = proj2_of_vec3(v);

    /** allow for optical distortion **/
    if (cam->distort_params != NULL &&      cam->distort_func != NULL)
        w = cam->distort_func(w, cam->distort_params);

    /** change to image coordinates **/
    w = rectify_pos(cam->cam_to_im, w);

The macro proj2_of_vec3 takes the Vec3 (x, y, z) to the Vec2 (x/z, y/z). The function

Vec2    rectify_pos(Mat3 rect, Vec2 p)

applies the projective transform represented by P to image coords q and returns new image coordinates.

next up previous contents
Next: Parallel Stereo Camera Geometry Up: Camera Geometry Previous: Introduction   Contents
root 2019-03-24