latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiSkinProbabilityMap.h 00027 * authors ....: Benjamin Winkler 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 30.1.2001 00030 * revisions ..: $Id: ltiSkinProbabilityMap.h,v 1.8 2006/09/05 10:31:45 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_SKIN_PROBABILITY_MAP_H_ 00034 #define _LTI_SKIN_PROBABILITY_MAP_H_ 00035 00036 00037 #include "ltiProbabilityMap.h" 00038 #include "ltiLispStreamHandler.h" 00039 #include <fstream> 00040 00041 namespace lti { 00042 /** 00043 * creates a skin probability map. 00044 * 00045 * the histograms were generated from 3077 pictures containing 00046 * masked skin regions and 6286 pictures not containing skin, which 00047 * were taken from the compaq cambridge research lab image-database. 00048 * Please cite "M. Jones, J. Rehg. Statistical Color Models with 00049 * Application to Skin Color Detection. Compaq Cambridge Research 00050 * Lab Technical Report CRL 98/11, 1998." when using in a publication. 00051 * 00052 * the color models are located in "skin-32-32-32.hist" and 00053 * "nonskin-32-32-32.hist", saved in lisp format and must reside in 00054 * the current directory, or the path must be specified in the constructor. 00055 * 00056 * This class just keeps the two color models (for skin and non-skin) and 00057 * is responsible to load the on time. All computations are taken by the 00058 * parent class lti::probabilityMap 00059 */ 00060 class skinProbabilityMap : public probabilityMap { 00061 public: 00062 /** 00063 * the parameters for the class skinProbabilityMap. 00064 */ 00065 class parameters : public probabilityMap::parameters { 00066 public: 00067 /** 00068 * default constructor 00069 */ 00070 parameters(); 00071 00072 /** 00073 * copy constructor 00074 * @param other the parameters object to be copied 00075 */ 00076 parameters(const parameters& other); 00077 00078 /** 00079 * destructor 00080 */ 00081 ~parameters(); 00082 00083 /** 00084 * returns name of this type 00085 */ 00086 const char* getTypeName() const; 00087 00088 /** 00089 * copy the contents of a parameters object 00090 * @param other the parameters object to be copied 00091 * @return a reference to this parameters object 00092 */ 00093 parameters& copy(const parameters& other); 00094 00095 /** 00096 * copy the contents of a parameters object 00097 * @param other the parameters object to be copied 00098 * @return a reference to this parameters object 00099 */ 00100 parameters& operator=(const parameters& other); 00101 00102 /** 00103 * returns a pointer to a clone of the parameters 00104 */ 00105 virtual functor::parameters* clone() const; 00106 00107 /** 00108 * write the parameters in the given ioHandler 00109 * @param handler the ioHandler to be used 00110 * @param complete if true (the default) the enclosing begin/end will 00111 * be also written, otherwise only the data block will be written. 00112 * @return true if write was successful 00113 */ 00114 virtual bool write(ioHandler& handler,const bool complete=true) const; 00115 00116 /** 00117 * write the parameters in the given ioHandler 00118 * @param handler the ioHandler to be used 00119 * @param complete if true (the default) the enclosing begin/end will 00120 * be also written, otherwise only the data block will be written. 00121 * @return true if write was successful 00122 */ 00123 virtual bool read(ioHandler& handler,const bool complete=true); 00124 00125 # ifdef _LTI_MSC_6 00126 /** 00127 * this function is required by MSVC only, as a workaround for a 00128 * very awful bug, which exists since MSVC V.4.0, and still by 00129 * V.6.0 with all bugfixes (so called "service packs") remains 00130 * there... This method is also public due to another bug, so please 00131 * NEVER EVER call this method directly: use read() instead 00132 */ 00133 bool readMS(ioHandler& handler,const bool complete=true); 00134 00135 /** 00136 * this function is required by MSVC only, as a workaround for a 00137 * very awful bug, which exists since MSVC V.4.0, and still by 00138 * V.6.0 with all bugfixes (so called "service packs") remains 00139 * there... This method is also public due to another bug, so please 00140 * NEVER EVER call this method directly: use write() instead 00141 */ 00142 bool writeMS(ioHandler& handler,const bool complete=true) const; 00143 # endif 00144 00145 // ------------------------------------------------ 00146 // the parameters 00147 // ------------------------------------------------ 00148 00149 // If you add more parameters manually, do not forget to do following: 00150 // 1. indicate in the default constructor the default values 00151 // 2. make sure that the copy member also copy your new parameters 00152 // 3. make sure that the read and write members also read and 00153 // write your parameters 00154 00155 /** 00156 * assumed overall probability of any pixel being skin (default is 0.5) 00157 * This is an alias for the attribute of the parent class 00158 * "objectProbability". 00159 */ 00160 float& skinProbability; 00161 00162 /** 00163 * path where the skin probability histograms can be found. 00164 * 00165 * The two files expected here are: <code>skin-32-32-32.hist</code> 00166 * and <code>nonskin-32-32-32.hist</code>. These will be readed as 00167 * soon as the parameters are set. 00168 * 00169 * These files can be generated writing the lti::histogram objets with 00170 * their own write method using an lti::lispStreamHandler object. 00171 * 00172 */ 00173 std::string path; 00174 }; 00175 00176 /** 00177 * default constructor 00178 * This constructor will initialize the functor with the default 00179 * parameters. If you require to set the parameters later, you can 00180 * give in the boolean <code>useDefaultParams</code> the value "false". 00181 * This way the histograms will be loaded when you set the parameters. 00182 */ 00183 skinProbabilityMap(const bool& useDefaultParams = true); 00184 00185 /** 00186 * constructor with path 00187 * @param path this parameter specify the path where 00188 * the skin histogram files can be found, and loads them. 00189 */ 00190 skinProbabilityMap(const std::string path); 00191 00192 /** 00193 * constructor with path 00194 * @param path this parameter specify the path where 00195 * the skin histogram files can be found, and loads them. 00196 */ 00197 skinProbabilityMap(const char* path); 00198 00199 /** 00200 * default constructor 00201 * @param param The parameters contain the path where 00202 * the skin histogram file can be found, which will be 00203 * loaded here. If you need to wait with the histograms 00204 * initialization until the user specifies a path setting 00205 * the parameters, you should use the default constructor. 00206 */ 00207 skinProbabilityMap(const parameters& param); 00208 00209 00210 /** 00211 * copy constructor 00212 * @param other the object to be copied 00213 */ 00214 skinProbabilityMap(const skinProbabilityMap& other); 00215 00216 /** 00217 * destructor 00218 */ 00219 virtual ~skinProbabilityMap(); 00220 00221 /** 00222 * returns the name of this type ("skinProbabilityMap") 00223 */ 00224 virtual const char* getTypeName() const; 00225 00226 /** 00227 * copy data of "other" functor. 00228 * @param other the functor to be copied 00229 * @return a reference to this functor object 00230 */ 00231 skinProbabilityMap& copy(const skinProbabilityMap& other); 00232 00233 /** 00234 * returns a pointer to a clone of this functor. 00235 */ 00236 virtual functor* clone() const; 00237 00238 /** 00239 * returns used parameters 00240 */ 00241 const parameters& getParameters() const; 00242 00243 /** 00244 * get a const reference to the skin color model 00245 */ 00246 static const thistogram<double>& getSkinHistogram(); 00247 00248 /** 00249 * get a const reference to the non-skin color model 00250 */ 00251 static const thistogram<double>& getNonSkinHistogram(); 00252 00253 private: 00254 00255 /** 00256 * Generate skin probability histogram. 00257 * 00258 * This is automatically called in the setParameters() method. 00259 */ 00260 virtual bool generate(); 00261 00262 /** 00263 * skin model 00264 */ 00265 static const thistogram<double> theSkinModel; 00266 00267 /** 00268 * non-skin model 00269 */ 00270 static const thistogram<double> theNonSkinModel; 00271 00272 /** 00273 * initialization flag 00274 */ 00275 static bool initialized; 00276 00277 /** 00278 * this member initialize (load) the histograms 00279 */ 00280 void initialize(); 00281 00282 00283 }; 00284 } 00285 00286 #endif