Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

SearcherPyramid.h

Go to the documentation of this file.
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 
00024 class SearcherPyramid : public SearcherBase
00025 {
00026 public:
00027     SearcherPyramid()
00028     {
00029         mTemplatePyramid = 0;
00030         mInputPyramid = 0;
00031     }
00032 
00033     virtual ~SearcherPyramid()
00034     {
00035         if(mTemplatePyramid)
00036             delete mTemplatePyramid;
00037         if(mInputPyramid)
00038             delete mInputPyramid;
00039     }
00040 
00041     virtual void SearchObject(Array::Array2dVec3Real64& image)
00042     {
00043         if(mTemplatePyramid == 0)
00044             return;
00045 
00046         mInputPyramid->PropagateBaseChanges();
00047         mTemplatePyramid->PropagateBaseChanges();
00048 
00049         //search in the highest level in both pyramids (template is always the smaller)
00050         int level = mTemplatePyramid->Levels()-1;
00051         Point searchSize(mInputPyramid->GetSize(level));
00052         Point searchPos(0, 0);
00053         Point searchBorder(mInputPyramid->GetSize(0));
00054 
00055         Array::Array2dVec3Real64* searchArea;
00056         Array::Array2dVec3Real64* searchResult;
00057         searchArea = new Array::Array2dVec3Real64(searchSize.x + 2*searchBorder.x, searchSize.y + 2*searchBorder.y, 0, 0, 0);
00058         searchResult = new Array::Array2dVec3Real64(searchSize.x + 2*searchBorder.x, searchSize.y + 2*searchBorder.y, 0, 0, 0);
00059 
00060         Array::Trait::FuncExportMinMax<Array::Vec3Real64, Array::Array2dVec3Real64> minmax;
00061         Array::Trait::FuncBpoManhatDist dist;
00062         Array::Trait::FuncBpoAddAssignPtr bpoAss;
00063 
00064         while(level>=0)
00065         {
00066             searchBorder.x = mTemplatePyramid->GetLevel(level)->CW();
00067             searchBorder.y = mTemplatePyramid->GetLevel(level)->CH();
00068 
00069             searchArea->mCW = 2*searchBorder.x + searchSize.x;
00070             searchArea->mCH = 2*searchBorder.y + searchSize.y;
00071             searchArea->mBW = 0;
00072             searchArea->mBH = 0;
00073             Array::Pattern::PatSet(searchArea, mInputPyramid->GetLevel(level), searchPos.x - searchBorder.x, searchPos.y - searchBorder.y, searchSize.x + 2*searchBorder.x, searchSize.y + 2*searchBorder.y, 0, 0);
00074             searchArea->mCW = searchSize.x;
00075             searchArea->mCH = searchSize.y;
00076             searchArea->mBW = searchBorder.x;
00077             searchArea->mBH = searchBorder.y;
00078             searchResult->mCW = searchSize.x;
00079             searchResult->mCH = searchSize.y;
00080             searchResult->mBW = searchBorder.x;
00081             searchResult->mBH = searchBorder.y;
00082 
00083             Array::Pattern::FuncGenConv2dDispatch(searchResult, searchArea, mTemplatePyramid->GetLevel(level), dist, bpoAss);
00084 
00085             minmax.Reset();
00086             Array::Pattern::PatInOutOp(searchResult, minmax);
00087 
00088             minmax.minPos.mX += searchPos.x;
00089             minmax.minPos.mY += searchPos.y;
00090 
00091             if(level>0)
00092             {
00093                 minmax.minPos *= 2;
00094                 searchPos.x = minmax.minPos.mX - 1;
00095                 searchPos.y = minmax.minPos.mY - 1;
00096                 searchSize.x = 3;
00097                 searchSize.y = 3;
00098                 //clip
00099                 Point max = mInputPyramid->GetSize(level-1);
00100                 if(searchPos.x < 0)
00101                     searchPos.x = 0;
00102                 if(searchPos.y < 0)
00103                     searchPos.y = 0;
00104                 if(searchPos.x > max.x - 4)
00105                     searchPos.x = max.x - 4;
00106                 if(searchPos.y > max.y - 4)
00107                     searchPos.y = max.y - 4;
00108             }
00109             level--;
00110         }
00111         mLastPos.translation.x = minmax.minPos.mX - mLastPos.size.x/2;
00112         mLastPos.translation.y = minmax.minPos.mY - mLastPos.size.y/2;
00113 
00114         delete searchResult;
00115         delete searchArea;
00116         
00117     }
00118 
00119     //never used?
00120     //Array::Array2dVec3Real64* CreateSearchArea(Array::Array2dVec3Real64* src, const Rect& area, const Point& templateSize);
00121 
00122     void Reset(Array::Array2dVec3Real64& image, ObjectRepresentation& object, const Position& pos)
00123     {
00124         if(mInputPyramid)
00125             delete mInputPyramid;
00126         mInputPyramid = new ImagePyramid(&image);
00127         mInputPyramid->ComputeLevels(0);
00128 
00129         if(mTemplatePyramid)
00130             delete mTemplatePyramid;
00131         mTemplatePyramid = 0;
00132         Array::Array2dVec3Real64* obj = object.GetImage();
00133         if(obj)
00134         {
00135             ILOG_DEBUG("obj not null");
00136             mTemplatePyramid = new ImagePyramid(object.GetImage());
00137             mTemplatePyramid->ComputeLevels(0);
00138         }
00139         else
00140         {
00141             ILOG_WARN("object image null!");
00142         }
00143 
00144         mLastPos = pos;
00145     }
00146 
00148     ImagePyramid* mInputPyramid;
00150     ImagePyramid* mTemplatePyramid;
00151 
00152     static log4cpp::Category& sLog;
00153 };
00154 
00155 ILOG_VAR_INIT(SearcherPyramid, Impala.Core.Tracking);
00156 
00157 } // namespace Tracking
00158 } // namespace Core
00159 } // namespace Impala
00160 
00161 #endif //Impala_Core_Tracking_SearcherPyramid_h

Generated on Fri Mar 19 09:31:23 2010 for ImpalaSrc by  doxygen 1.5.1