00001 #ifndef Impala_Core_Tracking_SearcherPyramid_h
00002 #define Impala_Core_Tracking_SearcherPyramid_h
00003
00004 #include "Core/Array/Pattern/PatSet.h"
00005 #include "Core/Array/Pattern/FuncGenConv2d.h"
00006
00007 #include "Core/Tracking/SearcherBase.h"
00008 #include "Core/Tracking/Functors.h"
00009 #include "Core/Tracking/ObjectRepresentation.h"
00010 #include "Core/Tracking/ImagePyramid.h"
00011
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace Tracking
00017 {
00018
00023 class SearcherPyramid : public SearcherBase
00024 {
00025 public:
00026 SearcherPyramid()
00027 {
00028 mTemplatePyramid = 0;
00029 mInputPyramid = 0;
00030 }
00031
00032 virtual ~SearcherPyramid()
00033 {
00034 if(mTemplatePyramid)
00035 delete mTemplatePyramid;
00036 if(mInputPyramid)
00037 delete mInputPyramid;
00038 }
00039
00040 virtual void
00041 SearchObject(Array::Array2dVec3Real64& image)
00042 {
00043 if(mTemplatePyramid == 0)
00044 return;
00045
00046 mInputPyramid->PropagateBaseChanges();
00047 mTemplatePyramid->PropagateBaseChanges();
00048
00049
00050
00051 int level = mTemplatePyramid->Levels()-1;
00052 Point searchSize(mInputPyramid->GetSize(level));
00053 Point searchPos(0, 0);
00054 Point searchBorder(mInputPyramid->GetSize(0));
00055
00056 Array::Array2dVec3Real64* searchArea;
00057 Array::Array2dVec3Real64* searchResult;
00058 searchArea =
00059 new Array::Array2dVec3Real64(searchSize.x + 2*searchBorder.x,
00060 searchSize.y + 2*searchBorder.y, 0, 0, 0);
00061 searchResult =
00062 new Array::Array2dVec3Real64(searchSize.x + 2*searchBorder.x,
00063 searchSize.y + 2*searchBorder.y, 0, 0, 0);
00064
00065 Array::Trait::FuncExportMinMax<Array::Vec3Real64,
00066 Array::Array2dVec3Real64> minmax;
00067 Array::Trait::FuncBpoManhatDist dist;
00068 Array::Trait::FuncBpoAddAssignPtr bpoAss;
00069
00070 while(level>=0)
00071 {
00072 searchBorder.x = mTemplatePyramid->GetLevel(level)->CW();
00073 searchBorder.y = mTemplatePyramid->GetLevel(level)->CH();
00074
00075 searchArea->mCW = 2*searchBorder.x + searchSize.x;
00076 searchArea->mCH = 2*searchBorder.y + searchSize.y;
00077 searchArea->mBW = 0;
00078 searchArea->mBH = 0;
00079 Array::Pattern::PatSet(searchArea, mInputPyramid->GetLevel(level),
00080 searchPos.x - searchBorder.x,
00081 searchPos.y - searchBorder.y,
00082 searchSize.x + 2*searchBorder.x,
00083 searchSize.y + 2*searchBorder.y, 0, 0);
00084 searchArea->mCW = searchSize.x;
00085 searchArea->mCH = searchSize.y;
00086 searchArea->mBW = searchBorder.x;
00087 searchArea->mBH = searchBorder.y;
00088 searchResult->mCW = searchSize.x;
00089 searchResult->mCH = searchSize.y;
00090 searchResult->mBW = searchBorder.x;
00091 searchResult->mBH = searchBorder.y;
00092
00093 Array::Pattern::FuncGenConv2dDispatch(searchResult, searchArea,
00094 mTemplatePyramid->GetLevel(level),
00095 dist, bpoAss);
00096
00097 minmax.Reset();
00098 Array::Pattern::PatInOutOp(searchResult, minmax);
00099
00100 minmax.minPos.mX += searchPos.x;
00101 minmax.minPos.mY += searchPos.y;
00102
00103 if(level>0)
00104 {
00105 minmax.minPos *= 2;
00106 searchPos.x = minmax.minPos.mX - 1;
00107 searchPos.y = minmax.minPos.mY - 1;
00108 searchSize.x = 3;
00109 searchSize.y = 3;
00110
00111 Point max = mInputPyramid->GetSize(level-1);
00112 if(searchPos.x < 0)
00113 searchPos.x = 0;
00114 if(searchPos.y < 0)
00115 searchPos.y = 0;
00116 if(searchPos.x > max.x - 4)
00117 searchPos.x = max.x - 4;
00118 if(searchPos.y > max.y - 4)
00119 searchPos.y = max.y - 4;
00120 }
00121 level--;
00122 }
00123 mLastPos.translation.x = minmax.minPos.mX - mLastPos.size.x/2;
00124 mLastPos.translation.y = minmax.minPos.mY - mLastPos.size.y/2;
00125
00126 delete searchResult;
00127 delete searchArea;
00128
00129 }
00130
00131 void
00132 Reset(Array::Array2dVec3Real64& image, ObjectRepresentation& object,
00133 const Position& pos)
00134 {
00135 if(mInputPyramid)
00136 delete mInputPyramid;
00137 mInputPyramid = new ImagePyramid(&image);
00138 mInputPyramid->ComputeLevels(0);
00139
00140 if(mTemplatePyramid)
00141 delete mTemplatePyramid;
00142 mTemplatePyramid = 0;
00143 Array::Array2dVec3Real64* obj = object.GetImage();
00144 if(obj)
00145 {
00146 ILOG_DEBUG("obj not null");
00147 mTemplatePyramid = new ImagePyramid(object.GetImage());
00148 mTemplatePyramid->ComputeLevels(0);
00149 }
00150 else
00151 {
00152 ILOG_WARN("object image null!");
00153 }
00154
00155 mLastPos = pos;
00156 }
00157
00159 ImagePyramid* mInputPyramid;
00161 ImagePyramid* mTemplatePyramid;
00162
00163 static log4cpp::Category& sLog;
00164 };
00165
00166 ILOG_VAR_INIT(SearcherPyramid, Impala.Core.Tracking);
00167
00168 }
00169 }
00170 }
00171
00172 #endif //Impala_Core_Tracking_SearcherPyramid_h