Kiretu
|
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 FrameGrabber.h 00021 * 00022 * Header file of the FrameGrabber-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 FrameGrabber 00029 */ 00030 00031 #include <stdint.h> 00032 #include <iostream> 00033 #include <cmath> 00034 00035 #include <algorithm> 00036 #include <vector> 00037 00038 /** \class FrameGrabber 00039 * \brief C++-class for grabbing both depth-images and RGB-images. Due to 00040 * the varying quality of Kinects depth-reconstruction, a desired 00041 * number of depth-frames can be taken an the mean of the valid 00042 * depth-values is used as the resulting depth-value. To prevent 00043 * outliers, the standard deviation is used as a threshold of valid 00044 * values. 00045 * 00046 * \author Daniel Wunderlich (d.wunderlich@stud.uni-heidelberg.de) 00047 * \version 0.5 00048 * \date 2011-01-26 00049 * 00050 * \see \ref framegrabber-section 00051 */ 00052 class FrameGrabber { 00053 00054 public: 00055 00056 /** \brief Constructor of the FrameGrabber-class. 00057 * 00058 * \param numberFrames The number of depth-images (frames) should be taken. 00059 * 00060 * \param sdThreshold Threshold for the maximum standard deviation of the 00061 * z-values in each frame. If the threshold is 00062 * exceeded, the z-value is not valid. 00063 * 00064 * \see framegrabber-section 00065 */ 00066 FrameGrabber(unsigned int numberFrames, unsigned int sdThreshold = 5.0); 00067 00068 00069 /** \brief Destructor of the FrameGrabber-class. 00070 */ 00071 ~FrameGrabber(); 00072 00073 00074 /** \brief Adds a Kinect depth-frame/image to the FrameGrabber-object. 00075 * 00076 * \param depth Depth-image of Microsoft's Kinect as used in the 00077 * glview-example of OpenKinect. 00078 * 00079 * \return True, if the frame was added. False, if the number of desired frames 00080 * specified at the constructor was already added. 00081 */ 00082 bool addFrame(uint16_t* depth); 00083 00084 00085 /** \brief Adds a Kinect RGB-frame/image to the FrameGrabber-object. 00086 * 00087 * \param rgb RGB-image of Microsoft's Kinect as used in the 00088 * glview-example of OpenKinect. 00089 */ 00090 void addRgb(uint8_t* rgb); 00091 00092 00093 /** \brief Computes the z-values (depth-values) of the image as the mean of all 00094 * valid depth-values per pixel. Depth-values, which standard deviation 00095 * is higher than specified at the constructor are sorted out 00096 * additional. 00097 */ 00098 void computeZValues(); 00099 00100 /** \brief Get the z-values (depth-values). 00101 * 00102 * \return int-Pointer to the \f$640 \times 480\f$-dimensional depth-value 00103 * array. 00104 */ 00105 int* getZValues(); 00106 00107 /** \brief Get the RGB-values. 00108 * 00109 * \return int-Pointer to the \f$640 \times 480\f$-dimensional RGB-value-array. 00110 */ 00111 int* getRgbValues(); 00112 00113 /** \brief Get the indicators of valid values. 00114 * 00115 * \return bool-Pointer to a \f$640 \times 480\f$-dimensional boolean-array, 00116 * which indicates, if the depth-value at corresponding index is valid. 00117 */ 00118 bool* getValidValues(); 00119 00120 00121 /** \brief Get the total number of valid values. 00122 * 00123 * \return Number of valid values. 00124 */ 00125 int getValidCount(); 00126 00127 private: 00128 unsigned int numberFrames; /**< Number of frames, which should be captured of the depth-stream. */ 00129 int countFrames; /**< Counts the number of frames already added to the FrameGrabber. */ 00130 int validCountTotal; /**< Counts the total number of valid depth-values. */ 00131 float sdThreshold; /**< Standard deviation threshold of valid depth-values. */ 00132 00133 int zValues[640*480]; /**< z-values (depth-values) */ 00134 int rgbValues[640*480*3]; /**< RGB-values */ 00135 bool validValues[640*480]; /**< Valid values */ 00136 int (* frames)[640*480]; /**< Buffer for all captured frames */ 00137 00138 00139 /** \brief Computes the standard deviation of one pixel's depth-values over all 00140 * frames. 00141 * 00142 * \param index Index of the pixel. 00143 * \param zMean Mean of the pixel's valid z-values (depth-values). 00144 * \param validCount Number of the pixel's valid z-values. 00145 * 00146 * \return Number of valid values. 00147 */ 00148 float computeSD(int index, int zMean, int validCount); 00149 };