Kiretu

/home/wu/Desktop/kiretu-0.8/YMLParser.h

Go to the documentation of this file.
00001 /* This file is part of the Kiretu, a Kinect reconstruction tutor.
00002  * 
00003  * http://pille.iwr.uni-heidelberg.de/~kinect01/
00004  * 
00005  * The code ist licensed to you under the terms of the GNU General Public 
00006  * License, version 2.0. See the GPL2 file for the text of the license or the 
00007  * following URL:
00008  * 
00009  * http://www.gnu.org/licenses/gpl-2.0.txt
00010  * 
00011  * If you redistribute this file in source form, modified or unmodified, you
00012  * have to leave this header intact and distribute it under the same terms with 
00013  * the GPL2 file.
00014  * 
00015  * Binary distributions must follow the binary distribution requirements of
00016  * the License.
00017  * 
00018  */
00019  
00020  /** \file YMLParser.h
00021  * 
00022  * Header file of the YMLParser-class.
00023  * 
00024  * \author      Daniel Wunderlich (d.wunderlich@stud.uni-heidelberg.de)
00025  * \version     0.8
00026  * \date        2011-01-26
00027  *  
00028  * \see     \ref YMLParser
00029  */
00030 
00031 #include <vector>
00032 #include <fstream>
00033 #include <sstream>
00034 #include <string>
00035 #include <cstring>
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <iostream>
00039 
00040 #include "Util.h"
00041 
00042 /** \brief  Parameter-types of the Kinect.
00043  */
00044 enum KinectParam
00045 {
00046     RGB_INTRINSICS,     /**< Intrinsics of the RGB-camera */
00047     RGB_DISTORTION,     /**< Distortion-parameters of the RGB-camera */
00048     DEPTH_INTRINSICS,   /**< Intrinsics of the depth-camera */
00049     DEPTH_DISTORTION,   /**< Distortion-parameters of the depth-camera */
00050     ROT,                /**< Rotation-matrix R */
00051     TRANS,              /**< Translation-vector t */
00052     PARAM_END           /**< Dummy parameter for recognize the end of enum */
00053 };
00054 
00055 /** \class  YMLParser 
00056  *  \brief  C++-class for read in a Kinect yml calibration file and extract the 
00057  *          intrinsic and extrisic parameters of the Kinect.
00058  *  
00059  *  \author Daniel Wunderlich (d.wunderlich@stud.uni-heidelberg.de)
00060  *  \version 0.8
00061  *  \date   2011-01-26
00062  *  
00063  *  \see    \ref reconstruction and \ref calibration
00064  */
00065 class YMLParser {
00066     
00067     public:
00068 
00069 /** \brief Constructor of the YMLParser-class.
00070  *  
00071  *  \param  filename    /Path/to/calibrationfile.yml
00072  */ 
00073         YMLParser(const std::string filename);
00074 
00075 /** \brief Deconstructor of the YMLParser-class.
00076  */ 
00077         ~YMLParser();
00078 
00079 /** \brief  Reads and parses the yml-file specified at the constructor and saves 
00080  *          the calibration parameters in the equivalent member variables of the 
00081  *          class.
00082  */         
00083         void parseFile();
00084         
00085         
00086         // Getter
00087 /** \brief  Get the intrinsics of the rgb-camera.
00088  * 
00089  * \return  A camera-matrix containing the intrinsic parameters of the 
00090  *          RGB-camera:
00091  *          \f[
00092  *              \mathbf{C} = 
00093  *              \begin{pmatrix}
00094  *                  f_x & 0 & c_x \\
00095  *                  0 & f_y & c_y \\
00096  *                  0 & 0 & 1
00097  *              \end{pmatrix}
00098  *          \f]
00099  */
00100         std::vector< std::vector<float> > getRgbCam();
00101         
00102 
00103 /** \brief  Get the distortion coefficients of the RGB-camera.
00104  * 
00105  * \return  A vector containing the distortion coefficients of the RGB-camera.
00106  */
00107         std::vector<float> getRgbDist();
00108         
00109 
00110 /** \brief  Get the intrinsics of the depth-camera.
00111  * 
00112  * \return  A camera-matrix containing the intrinsic parameters of the 
00113  *          depth-camera:
00114  *          \f[
00115  *              \mathbf{C} = 
00116  *              \begin{pmatrix}
00117  *                  f_x & 0 & c_x \\
00118  *                  0 & f_y & c_y \\
00119  *                  0 & 0 & 1
00120  *              \end{pmatrix}
00121  *          \f]
00122  */
00123         std::vector< std::vector<float> > getDepthCam();
00124         
00125 
00126 /** \brief  Get the distortion coefficients of the depth-camera.
00127  * 
00128  * \return  A vector containing the distortion coefficients of the depth-camera.
00129  */
00130         std::vector<float> getDepthDist();
00131         
00132         
00133 /** \brief  Get the rotation-matrix of the Kinect.
00134  * 
00135  * \return  Rotation-matrix of the Kinect:
00136  *          \f[
00137  *              \mathbf{T} =
00138  *              \begin{pmatrix}
00139  *                  r_{11} & r_{12} & r_{13}\\
00140  *                  r_{21} & r_{22} & r_{23}\\
00141  *                  r_{31} & r_{32} & r_{33}
00142  *              \end{pmatrix}
00143  *          \f]
00144  */
00145         std::vector< std::vector<float> > getRot();
00146         
00147 
00148 /** \brief  Get the translation-vector of the Kinect.
00149  * 
00150  * \return  Translation-vector of the Kinect:
00151  *          \f[
00152  *              \mathbf{T} =
00153  *              \begin{pmatrix}
00154  *                  t_1 \\
00155  *                  t_2 \\
00156  *                  t_3
00157  *              \end{pmatrix}
00158  *          \f]
00159  */
00160         std::vector<float> getTrans();
00161     
00162     private:
00163         std::string filename;       /**< Path and filename of the yml file */
00164         std::string text;           /**< Content of the yml file */
00165         
00166         // RGB-camera intrinsics
00167         std::vector<std::vector<float> > rgbCam;    /**< Intrinsics of the RGB-camera. Saved as 3x3-matrix. */
00168         
00169         // RGB-camera distortion
00170         std::vector<float> rgbDist;                 /**< Distortion parameters of the RGB-camera. Saved as 5-dimensional vector. */
00171         
00172         // Depth-camera intrinsics
00173         std::vector<std::vector<float> > depthCam;  /**< Intrinsics of the depth-camera. Saved as 3x3-matrix. */
00174         
00175         // Depth-camera distortion
00176         std::vector<float> depthDist;               /**< Distortion parameters of the depth-camera. Saved as 5-dimensional vector. */
00177         
00178         // Rotation-matrix R
00179         std::vector<std::vector<float> > rot;       /**< Rotation-matrix (3x3) of the extrinsic camera-parameters */
00180         
00181         // Translation-vector t
00182         std::vector<float> trans;                   /**< Translation-vector (3-dimensional) of the extrinsic camera-parameters */
00183         
00184 /** \brief Reads in the calibration-file.
00185  */ 
00186         void readFile();
00187 
00188 /** \brief  Extracts the given KinectParam from the read in yml-file and stores 
00189  *          them in the equivalent member variables.
00190  *  
00191  *  \param  param   Parameter to extract.
00192  */ 
00193         void findParam(KinectParam param);
00194         
00195 /** \brief  Splits up a string of comma separated values as used in the yml file 
00196  *          and stores it in the given vector.
00197  *  
00198  *  \param  str         String of comma separated values: 
00199  *                      value1,value2,...,valueN. Notice that there should be no 
00200  *                      whitespace and no comma after the last value.
00201  *      
00202  *  \param  vec         The vector the parameters should be stored to. It is 
00203  *                      important that the vecor is initialized with the 
00204  *                      corresponding size/length.
00205  */ 
00206         void csvToVector(std::string str, std::vector<float> &vec); 
00207             
00208 /** \brief  Splits up a string of comma separated values as used in the yml file 
00209  *          and stores it in the given matrix.
00210  *  
00211  *  \param  str         String of comma separated values: 
00212  *                      value1,value2,...,valueN. Notice that there should be no 
00213  *                      whitespace and no comma after the last value.
00214  *      
00215  *  \param  mat         The matrix the parameters should be stored to. It is 
00216  *                      important that the matrix is initialized with the 
00217  *                      corresponding size/length.
00218  */ 
00219         void csvToMatrix(std::string str, std::vector< std::vector<float> > &mat);
00220 
00221 };
 All Data Structures Files Functions Variables Enumerations Enumerator
[Page Up]