The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mpisearchthread.h

Go to the documentation of this file.
00001 /*
00002  *  MPColorTracker.cpp
00003  *  
00004  *
00005  *  Created by John Hershey 2002.
00006  *  Copyright (c) 2003 Machine Perception Laboratory
00007  *  University of California San Diego.
00008  *  Please read the disclaimer and notes about redistribution
00009  *  at the end of this file.
00010  *
00011  *  Authors: John Hershey, Josh Susskind, Bret Fortenberry
00012  */
00013 #ifndef __MPISEARCHTHREAD_H_
00014 #define __MPISEARCHTHREAD_H_
00015 
00016 #include "preprocessor.h"
00017 #include "mpisearchFaceDetector.h"
00018 // #include "mpiprobsearch.h"
00019 #include "Averaging/exponentialaverager.h"
00020 #include "Images/color.h"
00021 #include "MPHistogramHue.h"
00022 #include "MPHistogram.h"
00023 #include "common.h"
00024 #include "Images/ffimage.h"
00025 
00026 #ifdef USEHUE
00027 #define NUMBINS 1440
00028 #else
00029 #define NUMBINS 32
00030 #endif
00031 
00032 /* ================================================================ */
00033 
00034 struct MPIBox{
00035         int left;
00036         int top;
00037         int right;
00038         int bottom;
00039         int getHeight() {return bottom-top;};
00040         int getWidth() {return right-left;};
00041         int getMidX() {return (int) ((bottom-top)/2);};
00042         int getMidY() {return (int) ((right-left)/2);};
00043         MPIBox() : left(0), top(0), right(0), bottom(0) {};
00044 };
00045 #ifndef square
00046 #define square(x) (pow ((x), (2)) )
00047 #endif
00048 
00049 
00050 
00051 /* ================================================================ */
00052 
00053 /* Implements threaded loop for running MPI search */
00054 class MPISearchThread {
00055 
00056         friend void StartThreadedTracker(void *); /* Entry point for MPI thread (cdecl) */
00057 
00058 private:
00059 
00060         MPISearchFaceDetector m_Detector;
00061         RGBTRIPLE *m_MyPixels;  /* For holding pixels that MPI will search */
00062 //      RImage<float> m_pixels;
00063 
00064 #ifdef USEHUE
00065         MPHistogramHue<float, NUMBINS> m_ProbColorGivenFace;
00066         MPHistogramHue<float, NUMBINS> m_ProbColorGivenBack;
00067         MPHistogramHue<float, NUMBINS> m_CurrentProbColorGivenFace;
00068         MPHistogramHue<float, NUMBINS> m_CurrentProbColorGivenBack;
00069         MPHistogramHue<float, NUMBINS> m_LogProbColorGivenFace;
00070         MPHistogramHue<float, NUMBINS> m_LogProbColorGivenBack;
00071 #else
00072         MPHistogram<float, NUMBINS> m_ProbColorGivenFace;
00073         MPHistogram<float, NUMBINS> m_ProbColorGivenBack;
00074         MPHistogram<float, NUMBINS> m_CurrentProbColorGivenFace;
00075         MPHistogram<float, NUMBINS> m_CurrentProbColorGivenBack;
00076         MPHistogram<float, NUMBINS> m_LogProbColorGivenFace;
00077         MPHistogram<float, NUMBINS> m_LogProbColorGivenBack;
00078 #endif
00079 
00080         int m_NumPixels, m_NumFaces;
00081         double m_ColorMeanX, m_ColorMeanY;
00082         double m_MPIMeanX, m_MPIMeanY;
00083         int m_bBoxX1, m_bBoxX2, m_bBoxY1, m_bBoxY2;
00084         int m_Width, m_Height, m_lastWidth, m_lastHeight;
00085 
00086         int m_shiftAmount;
00087         double m_LowV, m_HighV;
00088         bool m_ThreadRunning;
00089         int m_ResetTracker, mutex_ResetTracker;
00090         double m_llikePix, mutex_llikePix;
00091         FaceBoxList m_MPIBoxes;
00092         long m_lastFrame, m_curFrame;
00093         TIMETYPE m_TimeMPISearchBoxes;
00094         MPColorTools m_color;
00095 
00096         void Process();
00097         void GetHueMinMax( int, int, int, double &, int &, int & ); /* Translates rgb to hue and min/max values for hue */
00098         void InitColorModel();
00099         void UpdateColorModel(FaceBoxList & faces); /* update histogram bins */
00100         void CompareColorMPIMeans(Square box);
00101         void Search(FFImage<float> &pixels, FaceBoxList &faces); /* Call the mpi detector to search an image */
00102         void Search(int, FaceBoxList &faces); /* Call the mpi detector to search an image */
00103         void UpdateProbabilities();
00104         void UpdateTimeMPISearchBoxes(TIMETYPE t);
00105         TIMETYPE getCurTime();
00106         void shiftFaces(FaceBoxList &faces);
00107         void setShift();
00108 
00109         MUTEX_TYPE m_DataMutex;
00110         MUTEX_TYPE m_FaceMutex;
00111         MUTEX_TYPE m_ImageMutex;
00112         THREAD_TYPE m_ThreadHandle;
00113         THREAD_COND m_GotBufferFillRequest;
00114 
00115 
00116 public:
00117 
00118         MPISearchThread();      
00119         ~MPISearchThread();     
00120         void Start(); /* Starts the thread */
00121         static THREAD_RETURN_TYPE StartThreadedTracker(void *);
00122         void PutData(RGBTRIPLE *, int, int, int, int, int, long); /* Threadsafe routine to write data to private member variable */
00123 //      void GetColorModel(MPHistogram<float, NUMBINS> & face, MPHistogram<float, NUMBINS> & back, int *reset, double *llike);
00124 #ifdef USEHUE
00125         void GetColorModel(MPHistogramHue<float, NUMBINS> *, MPHistogramHue<float, NUMBINS> *, int *, double* llike);
00126 #else
00127         void GetColorModel(MPHistogram<float, NUMBINS> *, MPHistogram<float, NUMBINS> *, int *, double* llike);
00128 #endif
00129 
00130         inline TIMETYPE getTimeStamp() const { return m_TimeMPISearchBoxes; }
00131         inline long getLastFrame() const { return m_lastFrame; }
00132         double getElapsedTime();
00133         int GetMPIFaceBoxes(FaceBoxList &faceBoxes);
00134         int      GetNumFaces();
00135         inline RGBTRIPLE MPIBoxPixel(RGBTRIPLE x, double fadeAmount) const{     
00136                 x.rgbtGreen = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtGreen);       
00137                 x.rgbtBlue = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtBlue);
00138                 x.rgbtRed = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtRed);
00139                 return x;
00140         }
00141 
00142 
00144 //      ADDED FOR TESTING PURPOSES              ///
00145         #include "Images/color.h"
00146         MPColorTools m_Color;
00148 
00149 };
00150 
00151 /* ================================================================ */
00152 
00153 #endif //__MPISEARCHTHREAD_H_
00154 
00155 
00156 /*
00157  * 
00158  * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00159  * 
00160  *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00161  *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00162  *    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00163  * 
00164  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00165  * 
00166  */

Generated on Mon Nov 8 17:07:46 2004 for MPT by  doxygen 1.3.9.1