libeblearntools
/home/rex/ebltrunk/tools/libeblearntools/include/tracking_thread.h
00001 /***************************************************************************
00002  *   Copyright (C) 2010 by Pierre Sermanet *
00003  *   pierre.sermanet@gmail.com *
00004  *   All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Redistribution under a license not approved by the Open Source
00014  *       Initiative (http://www.opensource.org) must display the
00015  *       following acknowledgement in all advertising material:
00016  *        This product includes software developed at the Courant
00017  *        Institute of Mathematical Sciences (http://cims.nyu.edu).
00018  *     * The names of the authors may not be used to endorse or promote products
00019  *       derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00023  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00024  * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY
00025  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00026  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00028  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  ***************************************************************************/
00032 
00033 // Windows does not know linux/mac mutexes, TODO: implement windows mutexes
00034 #ifndef __WINDOWS__
00035 
00036 #ifndef TRACKING_THREAD_H_
00037 #define TRACKING_THREAD_H_
00038 
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <pthread.h>
00042 
00043 #include "thread.h"
00044 #include "detection_thread.h"
00045 #include "configuration.h"
00046 
00047 #ifdef __OPENCV__
00048 #include <opencv/cv.h>
00049 //#include "FastMatchTemplate.h"
00050 #endif
00051 
00052 using namespace std;
00053 
00054 namespace ebl {
00055 
00057   // A tracking thread class
00058 
00059   template <typename Tnet>
00060   class tracking_thread : public thread {
00061   public:
00064     tracking_thread(configuration &conf, const char *arg2);
00065     ~tracking_thread();
00066     
00068     virtual void execute();
00070     virtual bool get_data(vector<bbox*> &bboxes, idx<ubyte> &frame,
00071                           idx<ubyte> &tpl);
00072     
00073   private:
00076     void copy_bboxes(vector<bbox*> &bb);
00079     void set_out_updated();
00081     void draw(bbox *b);
00082 
00084     // private members
00085   private:
00086     configuration               &conf;
00087     const char                  *arg2;
00088     pthread_mutex_t              mutex_out;     
00089     idx<ubyte>                   frame;         
00090     idx<ubyte>                   detframe;      
00091     vector<bbox*>                bboxes;
00092     vector<bbox*>::iterator      ibox;
00093     bool                         out_updated;   
00094     detection_thread<Tnet>       dt;
00095     idx<ubyte>                   tpl;
00096   };
00097 
00098 } // end namespace ebl
00099 
00100 #include "tracking_thread.hpp"
00101 
00102 #endif /* TRACKING_THREAD_H_ */
00103 
00104 #endif /* __WINDOWS__ */