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
00024 class TrackerGeneralised : public Tracker
00025 {
00026 public:
00027 TrackerGeneralised(SearcherBase* s=0, ObjectRepresentation* o=0)
00028 {
00029 mWidth = 0;
00030 mHeight = 0;
00031 mScratch = 0;
00032 mInput = 0;
00033 if(o)
00034 mObject = o;
00035 else
00036 mObject = new ObjectRepresentation();
00037
00038 if(s)
00039 mSearcher = s;
00040 else
00041 mSearcher = new SearcherBase();
00042
00043 mTrack = 0;
00044 }
00045
00046 virtual ~TrackerGeneralised()
00047 {
00048 delete mObject;
00049 delete mSearcher;
00050 if(mScratch)
00051 delete mScratch;
00052 if(mInput)
00053 delete mInput;
00054 }
00055
00056 virtual void Initialize(Array::Array2dVec3UInt8* input, Tracking::FrameRegion* startPos, FrameRegionTable* resultTrack)
00057 {
00058 mTrack = resultTrack;
00059 if(mScratch)
00060 delete mScratch;
00061 if(mInput)
00062 delete mInput;
00063 mTrack->Add(*startPos);
00064 mWidth = input->CW();
00065 mHeight = input->CH();
00066 mScratch = new Array::Array2dVec3UInt8(mWidth, mHeight, 0, 0);
00067 mInput = new Array::Array2dVec3Real64(mWidth, mHeight, mWidth, mHeight);
00068
00069 Array::Pattern::PatSet(mInput,input,mWidth/2, mHeight/2);
00070 Geometry::Rectangle r = startPos->GetRectangle();
00071 NewPosition(r.mLeft, r.mTop, r.mRight, r.mBottom);
00072 }
00073
00082 void Process(Array::Array2dVec3UInt8* input)
00083 {
00084 Array::Pattern::PatSet(mInput,input,mWidth,mHeight);
00085
00086 mSearcher->SearchObject(*mInput);
00087 mPosition = mSearcher->mLastPos;
00088 Clip(mPosition);
00089 mObject->Update(*mInput, mPosition);
00090 Geometry::Rectangle r(mPosition.translation.x,
00091 mPosition.translation.y,
00092 mPosition.translation.x + mPosition.size.x,
00093 mPosition.translation.y + mPosition.size.y);
00094 mTrack->Add(r);
00095 }
00096
00097 bool ObjectVisible()
00098 {
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 return mPosition.size.Inproduct() > 0;
00112 }
00113
00114 Position GetPosition() {return mPosition;}
00115
00116 protected:
00117 ObjectRepresentation* mObject;
00118 SearcherBase* mSearcher;
00119 int mWidth, mHeight;
00121 Array::Array2dVec3UInt8* mScratch;
00123 Array::Array2dVec3Real64* mInput;
00129 Position mPosition;
00130 FrameRegionTable* mTrack;
00131
00143 void Clip(Position& pos)
00144 {
00145 if(pos.translation.x < 0)
00146 pos.translation.x = 0;
00147 if(pos.translation.y < 0)
00148 pos.translation.y = 0;
00149 if(pos.translation.x >= mWidth-pos.size.x)
00150 pos.translation.x = mWidth-pos.size.x-1;
00151 if(pos.translation.y >= mHeight-pos.size.y)
00152 pos.translation.y = mHeight-pos.size.y-1;
00153
00154 }
00155
00156 virtual void NewPosition(int left, int top, int right, int bottom)
00157 {
00158
00159 mPosition.translation.x = left;
00160 mPosition.translation.y = top;
00161 mPosition.size.x = right - left;
00162 mPosition.size.y = bottom - top;
00163 mObject->Reset(*mInput, mPosition);
00164 mSearcher->Reset(*mInput, *mObject, mPosition);
00165 delete mScratch;
00166 mScratch = new Array::Array2dVec3UInt8(mPosition.size.x*2, mPosition.size.y, 0, 0);
00167 }
00168
00169 static log4cpp::Category& sLog;
00170 };
00171
00172 ILOG_VAR_INIT(TrackerGeneralised, Impala.Core.Tracking);
00173
00174 }
00175 }
00176 }
00177
00178 #endif //Impala_Core_Tracking_TrackerGeneralised_h