00001 #ifndef Impala_Core_Tracking_TrackerGeneralised_h
00002 #define Impala_Core_Tracking_TrackerGeneralised_h
00003
00004 #include "Core/Stream/RgbDataSrc.h"
00005 #include "Core/Array/Pattern/PatSet.h"
00006
00007 #include "Core/Tracking/Tracker.h"
00008 #include "Core/Tracking/BasicTypes.h"
00009 #include "Core/Tracking/SearcherBase.h"
00010 #include "Core/Tracking/ObjectRepresentation.h"
00011
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace Tracking
00017 {
00018
00022 class TrackerGeneralised : public Tracker
00023 {
00024 public:
00025 TrackerGeneralised(SearcherBase* s=0, ObjectRepresentation* o=0)
00026 {
00027 mWidth = 0;
00028 mHeight = 0;
00029 mScratch = 0;
00030 mInput = 0;
00031 if(o)
00032 mObject = o;
00033 else
00034 mObject = new ObjectRepresentation();
00035
00036 if(s)
00037 mSearcher = s;
00038 else
00039 mSearcher = new SearcherBase();
00040
00041 mTrack = 0;
00042 }
00043
00044 virtual
00045 ~TrackerGeneralised()
00046 {
00047 delete mObject;
00048 delete mSearcher;
00049 if(mScratch)
00050 delete mScratch;
00051 if(mInput)
00052 delete mInput;
00053 }
00054
00055 virtual void
00056 Initialize(Array::Array2dVec3UInt8* input, Tracking::FrameRegion* startPos,
00057 FrameRegionTable* resultTrack)
00058 {
00059 mTrack = resultTrack;
00060 if(mScratch)
00061 delete mScratch;
00062 if(mInput)
00063 delete mInput;
00064 mTrack->Add(*startPos);
00065 mWidth = input->CW();
00066 mHeight = input->CH();
00067 mScratch = new Array::Array2dVec3UInt8(mWidth, mHeight, 0, 0);
00068 mInput = new Array::Array2dVec3Real64(mWidth, mHeight, mWidth, mHeight);
00069
00070 Array::Pattern::PatSet(mInput,input,mWidth/2, mHeight/2);
00071 Geometry::Rectangle r = startPos->GetRectangle();
00072 NewPosition(r.mLeft, r.mTop, r.mRight, r.mBottom);
00073 }
00074
00083 void
00084 Process(Array::Array2dVec3UInt8* input)
00085 {
00086 Array::Pattern::PatSet(mInput,input,mWidth,mHeight);
00087
00088 mSearcher->SearchObject(*mInput);
00089 mPosition = mSearcher->mLastPos;
00090 Clip(mPosition);
00091 mObject->Update(*mInput, mPosition);
00092 Geometry::Rectangle r(mPosition.translation.x,
00093 mPosition.translation.y,
00094 mPosition.translation.x + mPosition.size.x,
00095 mPosition.translation.y + mPosition.size.y);
00096 mTrack->Add(r);
00097 }
00098
00100 bool
00101 ObjectVisible()
00102 {
00103 return mPosition.size.Inproduct() > 0;
00104 }
00105
00107 Position
00108 GetPosition()
00109 {
00110 return mPosition;
00111 }
00112
00113 protected:
00125 void
00126 Clip(Position& pos)
00127 {
00128 if(pos.translation.x < 0)
00129 pos.translation.x = 0;
00130 if(pos.translation.y < 0)
00131 pos.translation.y = 0;
00132 if(pos.translation.x >= mWidth-pos.size.x)
00133 pos.translation.x = mWidth-pos.size.x-1;
00134 if(pos.translation.y >= mHeight-pos.size.y)
00135 pos.translation.y = mHeight-pos.size.y-1;
00136
00137 }
00138
00140 virtual
00141 void NewPosition(int left, int top, int right, int bottom)
00142 {
00143
00144 mPosition.translation.x = left;
00145 mPosition.translation.y = top;
00146 mPosition.size.x = right - left;
00147 mPosition.size.y = bottom - top;
00148 mObject->Reset(*mInput, mPosition);
00149 mSearcher->Reset(*mInput, *mObject, mPosition);
00150 delete mScratch;
00151 mScratch = new Array::Array2dVec3UInt8(mPosition.size.x*2, mPosition.size.y, 0, 0);
00152 }
00153
00154 ObjectRepresentation* mObject;
00155 SearcherBase* mSearcher;
00156 int mWidth, mHeight;
00157 FrameRegionTable* mTrack;
00158 Array::Array2dVec3UInt8* mScratch;
00159
00162 Array::Array2dVec3Real64* mInput;
00163
00169 Position mPosition;
00170
00171 static log4cpp::Category& sLog;
00172 };
00173
00174 ILOG_VAR_INIT(TrackerGeneralised, Impala.Core.Tracking);
00175
00176 }
00177 }
00178 }
00179
00180 #endif //Impala_Core_Tracking_TrackerGeneralised_h