Fawkes API  Fawkes Development Version
ccd_calibration.cpp
00001 /***************************************************************************
00002  *  ccd_calibration.cpp - Class defining a ccd camera calibration matrix K
00003  *
00004  *  Created: Thu May 08 13:53:00 2008
00005  *  Copyright  2008  Christof Rath <c.rath@student.tugraz.at>
00006  *
00007  ****************************************************************************/
00008 
00009 /*  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version. A runtime exception applies to
00013  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00021  */
00022 
00023 #include <models/camera/ccd_calibration.h>
00024 
00025 #include <cmath>
00026 
00027 namespace firevision {
00028 #if 0 /* just to make Emacs auto-indent happy */
00029 }
00030 #endif
00031 
00032 /** @class CCDCalibration <models/camera/ccd_calibration.h>
00033  * A Calibration matrix for a ccd camera
00034  * @author Christof Rath
00035  */
00036 
00037 /**Constructor.
00038  * @param ax is the scale factor in the x-coordinate direction
00039  * @param ay is the scale factor in the y-coordinate direction
00040  * @param x0 is the x-coordinate of the principal point
00041  * @param y0 is the y-coordinate of the principal point
00042  */
00043 CCDCalibration::CCDCalibration(float ax, float ay, float x0, float y0):
00044   Calibration()
00045 {
00046   Matrix k(3, 3);
00047   k(0, 0) = ax;
00048   k(1, 1) = ay;
00049   k(2, 2) = 1.f;
00050   k(0, 2) = x0;
00051   k(1, 2) = y0;
00052 
00053   K(k);
00054 }
00055 
00056 /**
00057  * Constructor.
00058  * @param hor_fov horizontal field of view [rad]
00059  * @param img_width width of the image [px]
00060  * @param img_height height of the image [px]
00061  */
00062 CCDCalibration::CCDCalibration(float hor_fov, unsigned int img_width, unsigned int img_height):
00063   Calibration()
00064 {
00065   float w = img_width;
00066   float h = img_height;
00067   float ver_fov = hor_fov * h / w;
00068 
00069   Matrix k(3, 3);
00070   k(0, 0) = w / (2.f * tanf(hor_fov / 2.f));
00071   k(1, 1) = h / (2.f * tanf(ver_fov / 2.f));
00072   k(2, 2) = 1.f;
00073   k(0, 2) = w / 2.f;
00074   k(1, 2) = h / 2.f;
00075 
00076   K(k);
00077 }
00078 
00079 /** Copy constructor.
00080  * @param cp the CCDCalibration to copy
00081  */
00082 CCDCalibration::CCDCalibration(const CCDCalibration& cp):
00083   Calibration()
00084 {
00085   K(cp.K());
00086 }
00087 
00088 /** Destructor.
00089  */
00090 CCDCalibration::~CCDCalibration()
00091 {
00092 }
00093 
00094 } // end namespace firevision