OmniAlgoVRFilterDetection.hh

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) Massimo Cora' 2006 <maxcvs@email.it>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef __OMNIALGO_VRFILTER_DETECTION_H__
00020 #define __OMNIALGO_VRFILTER_DETECTION_H__
00021 
00022 
00023 #include "../OmniConfig.hh"
00024 #include "../OmniConversion.hh"
00025 #include "../OmniGCardConverter.hh"
00026 #include "../OmniFastLookupTable.hh"
00027 #include "../OmniCallback.hh"
00028 
00029 // the testing stuff
00030 #include "../testing/CvFaceDetect.hh"
00031 #include "../testing/CvFaceTrack.hh"
00032 #include "../testing/CvVRFilter.hh"
00033 
00034 #include <cxtypes.h>
00035 #include <cv.h>
00036 #include <highgui.h>
00037 
00045 template <class ConverterT, class AngleT, class ImageT, class PointT>
00046 class OmniAlgoVRFilterDetection {
00047 public:
00054         OmniAlgoVRFilterDetection( OmniConversion<ConverterT, AngleT, ImageT, PointT> *conversion_klass,
00055                                                         IplImage *first_frame );
00056         virtual ~OmniAlgoVRFilterDetection();
00057         
00063         void loop_next_frame( IplImage* frame );
00064         
00068         void loop_stop();
00069 
00079         void register_image_callbacks( on_create_image_context_cb* create_image_context,
00080                                                                    on_image_do_action_cb* image_show,
00081                                                                    on_destroy_image_context_cb* destroy_image_context,
00082                                                                    void* callback_data
00083                                                                   );
00084         
00096         void register_all_image_callbacks( on_create_image_context_cb* create_image_context,
00097                                                                            on_image_do_action_cb* image_show,
00098                                                                            on_destroy_image_context_cb* destroy_image_context,
00099                                                                            void* callback_data_on_image_do_action
00100                                                                           );    
00101 
00102 private:                // functions
00104         on_create_image_context_cb* create_image_context;
00105         
00107         on_image_do_action_cb* image_show;
00108         
00110         on_destroy_image_context_cb* destroy_image_context;
00111                 
00112 private:                // data
00114         OmniConversion<ConverterT, AngleT, ImageT, PointT> *_conv;
00115         CvFaceTrack<ConverterT, AngleT> *_facetracking;
00116         CvFaceDetect *_facedetect;
00117         int _frames_count;
00118         
00119         void *_callback_data_image_cb;
00120         
00122         bool _is_running;       
00123 };
00124 
00125 
00126 
00127 
00131 
00132 template <class ConverterT, class AngleT, class ImageT, class PointT>
00133 OmniAlgoVRFilterDetection<ConverterT, AngleT, ImageT, PointT>::
00134 OmniAlgoVRFilterDetection( OmniConversion<ConverterT, AngleT, ImageT, PointT> *conversion_klass,
00135                                                    IplImage *first_frame ) : _conv( conversion_klass )
00136 {
00137         
00138         _is_running = false;
00139         _facedetect = new CvFaceDetect();
00140         _facetracking = new CvFaceTrack<ConverterT, AngleT>( _conv );
00141         
00142         _callback_data_image_cb = NULL;
00143         _frames_count = 0;
00144         
00145         // set the default callbacks. They can be changed with register_callbacks () call.
00146         register_image_callbacks( omnistuff_create_image_context, omnistuff_image_do_action, 
00147                                                           omnistuff_destroy_image_context, NULL );
00148         
00149         _is_running = true;
00150         
00151 }
00152 
00153 template <class ConverterT, class AngleT, class ImageT, class PointT>
00154 OmniAlgoVRFilterDetection<ConverterT, AngleT, ImageT, PointT>::
00155 ~OmniAlgoVRFilterDetection()
00156 {
00157         delete _conv;
00158         delete _facedetect;
00159         delete _facetracking;
00160 }
00161 
00162 template <class ConverterT, class AngleT, class ImageT, class PointT>
00163 void OmniAlgoVRFilterDetection<ConverterT, AngleT, ImageT, PointT>::loop_next_frame( IplImage* frame )
00164 {
00165         if ( !_is_running )
00166                 return; 
00167 
00168 
00169         // perform a check every other frame.
00170         if ( _frames_count %2 == 0) {
00171                 _frames_count = 0;
00172                 _facedetect->cvFaceDetect( frame,  DRAW_NONE );
00173 //              _facedetect->cvFaceDetect( frame,  DRAW_ALL );
00174                         
00175                 _facetracking->cvAddPoint2Track( _facedetect->faces );
00176         }
00177 
00178         _facetracking->cvTrackNextFrame( frame );       
00179         _frames_count++;
00180 }
00181 
00182 template <class ConverterT, class AngleT, class ImageT, class PointT>
00183 void OmniAlgoVRFilterDetection<ConverterT, AngleT, ImageT, PointT>::loop_stop()
00184 {
00185         _is_running = false;
00186 }
00187 
00188 
00189 template <class ConverterT, class AngleT, class ImageT, class PointT>
00190 void OmniAlgoVRFilterDetection<ConverterT, AngleT, ImageT, PointT>::
00191 register_image_callbacks( on_create_image_context_cb* create_image_context,
00192                                                   on_image_do_action_cb* image_show,
00193                                                   on_destroy_image_context_cb* destroy_image_context,
00194                                                   void* callback_data_on_image_cb )
00195 {
00196         this->create_image_context = create_image_context;
00197         this->image_show = image_show;
00198         this->destroy_image_context = destroy_image_context;
00199         this->_callback_data_image_cb = callback_data_on_image_cb;
00200 }
00201 
00202 
00203 template <class ConverterT, class AngleT, class ImageT, class PointT>
00204 void OmniAlgoVRFilterDetection<ConverterT, AngleT, ImageT, PointT>::register_all_image_callbacks( 
00205                                                                                 on_create_image_context_cb* create_image_context,
00206                                                                                 on_image_do_action_cb* image_show,
00207                                                                                 on_destroy_image_context_cb* destroy_image_context,
00208                                                                                 void* callback_data_on_image_cb )
00209 {
00210         // instances.
00211         _facetracking->register_image_callbacks( create_image_context, image_show, 
00212                                                           destroy_image_context, callback_data_on_image_cb );
00213 }
00214 
00215 #endif  /* __OMNIALGO_VRFILTER_DETECTION_H__ */
00216 

Generated on Tue Dec 26 10:32:38 2006 for Omnimeeting by  doxygen 1.4.7