www.pudn.com > colortracker.rar > mpisearchthread.h
/*
* MPColorTracker.cpp
*
*
* Created by John Hershey 2002.
* Copyright (c) 2003 Machine Perception Laboratory
* University of California San Diego.
* Please read the disclaimer and notes about redistribution
* at the end of this file.
*
* Authors: John Hershey, Josh Susskind, Bret Fortenberry
*/
#ifndef __MPISEARCHTHREAD_H_
#define __MPISEARCHTHREAD_H_
#include "preprocessor.h"
#include "mpisearchFaceDetector.h"
// #include "mpiprobsearch.h"
#include "Averaging/exponentialaverager.h"
#include "Images/color.h"
#include "MPHistogramHue.h"
#include "MPHistogram.h"
#include "common.h"
#include "Images/ffimage.h"
#ifdef USEHUE
#define NUMBINS 1440
#else
#define NUMBINS 32
#endif
/* ================================================================ */
struct MPIBox{
int left;
int top;
int right;
int bottom;
int getHeight() {return bottom-top;};
int getWidth() {return right-left;};
int getMidX() {return (int) ((bottom-top)/2);};
int getMidY() {return (int) ((right-left)/2);};
MPIBox() : left(0), top(0), right(0), bottom(0) {};
};
#ifndef square
#define square(x) (pow ((x), (2)) )
#endif
/* ================================================================ */
/* Implements threaded loop for running MPI search */
class MPISearchThread {
friend void StartThreadedTracker(void *); /* Entry point for MPI thread (cdecl) */
private:
MPISearchFaceDetector m_Detector;
RGBTRIPLE *m_MyPixels; /* For holding pixels that MPI will search */
// RImage m_pixels;
#ifdef USEHUE
MPHistogramHue m_ProbColorGivenFace;
MPHistogramHue m_ProbColorGivenBack;
MPHistogramHue m_CurrentProbColorGivenFace;
MPHistogramHue m_CurrentProbColorGivenBack;
MPHistogramHue m_LogProbColorGivenFace;
MPHistogramHue m_LogProbColorGivenBack;
#else
MPHistogram m_ProbColorGivenFace;
MPHistogram m_ProbColorGivenBack;
MPHistogram m_CurrentProbColorGivenFace;
MPHistogram m_CurrentProbColorGivenBack;
MPHistogram m_LogProbColorGivenFace;
MPHistogram m_LogProbColorGivenBack;
#endif
int m_NumPixels, m_NumFaces;
double m_ColorMeanX, m_ColorMeanY;
double m_MPIMeanX, m_MPIMeanY;
int m_bBoxX1, m_bBoxX2, m_bBoxY1, m_bBoxY2;
int m_Width, m_Height, m_lastWidth, m_lastHeight;
int m_shiftAmount;
double m_LowV, m_HighV;
bool m_ThreadRunning;
int m_ResetTracker, mutex_ResetTracker;
double m_llikePix, mutex_llikePix;
FaceBoxList m_MPIBoxes;
long m_lastFrame, m_curFrame;
TIMETYPE m_TimeMPISearchBoxes;
MPColorTools m_color;
void Process();
void GetHueMinMax( int, int, int, double &, int &, int & ); /* Translates rgb to hue and min/max values for hue */
void InitColorModel();
void UpdateColorModel(FaceBoxList & faces); /* update histogram bins */
void CompareColorMPIMeans(Square box);
void Search(FFImage &pixels, FaceBoxList &faces); /* Call the mpi detector to search an image */
void Search(int, FaceBoxList &faces); /* Call the mpi detector to search an image */
void UpdateProbabilities();
void UpdateTimeMPISearchBoxes(TIMETYPE t);
TIMETYPE getCurTime();
void shiftFaces(FaceBoxList &faces);
void setShift();
MUTEX_TYPE m_DataMutex;
MUTEX_TYPE m_FaceMutex;
MUTEX_TYPE m_ImageMutex;
THREAD_TYPE m_ThreadHandle;
THREAD_COND m_GotBufferFillRequest;
public:
MPISearchThread();
~MPISearchThread();
void Start(); /* Starts the thread */
static THREAD_RETURN_TYPE StartThreadedTracker(void *);
void PutData(RGBTRIPLE *, int, int, int, int, int, long); /* Threadsafe routine to write data to private member variable */
// void GetColorModel(MPHistogram & face, MPHistogram & back, int *reset, double *llike);
#ifdef USEHUE
void GetColorModel(MPHistogramHue *, MPHistogramHue *, int *, double* llike);
#else
void GetColorModel(MPHistogram *, MPHistogram *, int *, double* llike);
#endif
inline TIMETYPE getTimeStamp() const { return m_TimeMPISearchBoxes; }
inline long getLastFrame() const { return m_lastFrame; }
double getElapsedTime();
int GetMPIFaceBoxes(FaceBoxList &faceBoxes);
int GetNumFaces();
inline RGBTRIPLE MPIBoxPixel(RGBTRIPLE x, double fadeAmount) const{
x.rgbtGreen = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtGreen);
x.rgbtBlue = (unsigned char) (fadeAmount*255.0 + (1.0-fadeAmount)*(double) x.rgbtBlue);
x.rgbtRed = (unsigned char) ((1.0-fadeAmount)*(double) x.rgbtRed);
return x;
}
/////////////////////////////////////
// ADDED FOR TESTING PURPOSES ///
#include "Images/color.h"
MPColorTools m_Color;
/////////////////////////////////////
};
/* ================================================================ */
#endif //__MPISEARCHTHREAD_H_
/*
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
*
* 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.
*
*/