latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2000, 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 .......: ltiTemporalTemplate.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 4.12.2000 00030 * revisions ..: $Id: ltiTemporalTemplate.h,v 1.8 2006/02/08 11:56:24 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_TEMPORAL_TEMPLATE_H_ 00034 #define _LTI_TEMPORAL_TEMPLATE_H_ 00035 00036 #include "ltiObject.h" 00037 #include "ltiImage.h" 00038 #include "ltiTransform.h" 00039 00040 namespace lti { 00041 00042 /** 00043 * This functor implements temporal templates, as described by James 00044 * Davis and Aaron Bobick in "The Representation and Recognition of 00045 * Action Using Temporal Templates", MIT Media Lab, Tech. Report 402, 00046 * IEEE Conference on Computer Vision and Pattern Recognition (CVPR'97) 00047 * The apply()-methods return the calculated Motion-History-Image coded in 00048 * a channel, where the value 1.0 means there was motion between the last 00049 * two images. 00050 */ 00051 class temporalTemplate : public transform { 00052 public: 00053 /** 00054 * the parameters for the class temporalTemplate 00055 */ 00056 class parameters : public transform::parameters { 00057 public: 00058 /** 00059 * default constructor 00060 */ 00061 parameters(); 00062 00063 /** 00064 * copy constructor 00065 * @param other the parameters object to be copied 00066 */ 00067 parameters(const parameters& other); 00068 00069 /** 00070 * destructor 00071 */ 00072 ~parameters(); 00073 00074 /** 00075 * returns name of this type 00076 */ 00077 const char* getTypeName() const; 00078 00079 /** 00080 * copy the contents of a parameters object 00081 * @param other the parameters object to be copied 00082 * @return a reference to this parameters object 00083 */ 00084 parameters& copy(const parameters& other); 00085 00086 /** 00087 * copy the contents of a parameters object 00088 * @param other the parameters object to be copied 00089 * @return a reference to this parameters object 00090 */ 00091 parameters& operator=(const parameters& other); 00092 00093 /** 00094 * returns a pointer to a clone of the parameters 00095 */ 00096 virtual functor::parameters* clone() const; 00097 00098 /** 00099 * write the parameters in the given ioHandler 00100 * @param handler the ioHandler to be used 00101 * @param complete if true (the default) the enclosing begin/end will 00102 * be also written, otherwise only the data block will be written. 00103 * @return true if write was successful 00104 */ 00105 virtual bool write(ioHandler& handler,const bool complete=true) 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 read(ioHandler& handler,const bool complete=true); 00115 00116 # ifdef _LTI_MSC_6 00117 /** 00118 * this function is required by MSVC only, as a workaround for a 00119 * very awful bug, which exists since MSVC V.4.0, and still by 00120 * V.6.0 with all bugfixes (so called "service packs") remains 00121 * there... This method is also public due to another bug, so please 00122 * NEVER EVER call this method directly: use read() instead 00123 */ 00124 bool readMS(ioHandler& handler,const bool complete=true); 00125 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 write() instead 00132 */ 00133 bool writeMS(ioHandler& handler,const bool complete=true) const; 00134 # endif 00135 00136 // ------------------------------------------------ 00137 // the parameters 00138 // ------------------------------------------------ 00139 00140 /** 00141 * tau specify the number of images in the past to be considered for the 00142 * temporal template. Default value: 5 00143 */ 00144 int tau; 00145 00146 /** 00147 * The difference between the last two images will consider a pixel value 00148 * change as relevant only if the difference is greater as this value, or 00149 * if useAverage is true, as this value multiplied by the average. 00150 * Default value: 0.1 00151 */ 00152 float threshold; 00153 00154 /** 00155 * if useAverage is true, the average of the difference will be 00156 * considered to adapt the threshold, otherwise, the threshold 00157 * will be considered as it is. 00158 * Default value: false 00159 */ 00160 bool useAverage; 00161 }; 00162 00163 /** 00164 * default constructor 00165 */ 00166 temporalTemplate(); 00167 00168 /** 00169 * copy constructor 00170 * @param other the object to be copied 00171 */ 00172 temporalTemplate(const temporalTemplate& other); 00173 00174 /** 00175 * destructor 00176 */ 00177 virtual ~temporalTemplate(); 00178 00179 /** 00180 * returns the name of this type ( "temporalTemplate" ) 00181 */ 00182 virtual const char* getTypeName() const; 00183 00184 /** 00185 * reset the internal accumulators, so that the next apply will be 00186 * considered as the first image to detect motion 00187 */ 00188 void reset(); 00189 00190 /** 00191 * operates on the given %parameter. 00192 * @param srcdest channel with the source data. The result 00193 * will be left here too. 00194 * @return true if successful, false otherwise 00195 * Please note that all considered images MUST have the same size, 00196 * otherwise your previous information will be lost. The first 00197 * image will determine the used image size. You can restart with 00198 * another size using reset(). 00199 */ 00200 bool apply(channel& srcdest); 00201 00202 /** 00203 * operates on a copy of the given %parameters. 00204 * @param src image with the source data. 00205 * @param dest image where the result will be left. 00206 * @return true if successful, false otherwise 00207 * Please note that all considered images MUST have the same size, 00208 * otherwise your previous information will be lost. The first 00209 * images will determine the used image size. You can restart with 00210 * another size using reset(). 00211 */ 00212 bool apply(const image& src,channel& dest); 00213 00214 /** 00215 * operates on a copy of the given %parameters. 00216 * @param src channel with the source data. 00217 * @param dest channel where the result will be left. 00218 * @return true if successful, false otherwise 00219 * Please note that all considered images MUST have the same size, 00220 * otherwise your previous information will be lost. The first 00221 * images will determine the used image size. You can restart with 00222 * another size using reset(). 00223 */ 00224 bool apply(const channel& src,channel& dest); 00225 00226 /** 00227 * operates on a copy of the given %parameters. 00228 * @param src channel8 with the source data. 00229 * @param dest channel8 where the result will be left. 00230 * @return true if successful, false otherwise 00231 * Please note that all considered images MUST have the same size, 00232 * otherwise your previous information will be lost. The first 00233 * images will determine the used image size. You can restart with 00234 * another size using reset(). 00235 */ 00236 bool apply(const channel8& src,channel& dest); 00237 00238 /** 00239 * copy data of "other" functor. 00240 * @param other the functor to be copied 00241 * @return a reference to this functor object 00242 */ 00243 temporalTemplate& copy(const temporalTemplate& other); 00244 00245 /** 00246 * returns a pointer to a clone of this functor. 00247 */ 00248 virtual functor* clone() const; 00249 00250 /** 00251 * returns used parameters 00252 */ 00253 const parameters& getParameters() const; 00254 00255 protected: 00256 /** 00257 * calculates the difference image. The given image will substitute 00258 * the lastChannel, and at the end will be empty() 00259 * returns the threshold to be used. 00260 */ 00261 float difference(channel& newChannel, channel& diff); 00262 00263 /** 00264 * calculates the difference image. The given image will substitute 00265 * the lastChannel, and at the end will be empty() 00266 * returns the threshold to be used. 00267 */ 00268 float difference(channel8& newChannel, channel& diff); 00269 00270 /** 00271 * calculates the difference image. The given image will substitute 00272 * the lastChannel, and at the end will be empty() 00273 * returns the threshold to be used. 00274 */ 00275 float difference(image& newImage, channel& diff); 00276 00277 /** 00278 * accumulate the given difference image in the MHI. Diff will 00279 * contain the same value as mhi after calling this member. 00280 */ 00281 void accumulate(channel& diff,const float& threshold); 00282 00283 /** 00284 * the last channel, required to calculate D(x,y,t) 00285 */ 00286 channel lastChannel; 00287 00288 /** 00289 * the last channel8, required to calculate D(x,y,t) 00290 */ 00291 channel8 lastChannel8; 00292 00293 /** 00294 * the last image, required to calculate D(x,y,t) 00295 */ 00296 image lastImage; 00297 00298 /** 00299 * The Motion History Image 00300 */ 00301 channel mhi; 00302 }; 00303 } 00304 00305 #endif