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

SearcherAroundLastPos.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Tracking_SearcherAroundLastpos_h
00002 #define Impala_Core_Tracking_SearcherAroundLastpos_h
00003 
00004 #include "Core/Tracking/SearcherBase.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Tracking
00011 {
00012 
00013 class SearcherAroundLastPos : public SearcherBase
00014 {
00015 public:
00016     SearcherAroundLastPos()
00017     {
00018         mSampleSize = 300;
00019         mPosSigma = 20;
00020     }
00021 
00022     void SearchObject(Array::Array2dVec3Real64& image)
00023     {
00024         int i;
00025         double score, bestScore = 1e100; //high, todo: get high value from standard library
00026         Point bestPos;
00027         Array::Array2dVec3Real64* temp = new Array::Array2dVec3Real64(mLastPos.size.x, mLastPos.size.y, 0, 0);
00028         for(i=0 ; i<mSampleSize ; i++)
00029         {
00030             double x,y,sqr;
00031             // take 2 random numbers with normal distribution
00032             do
00033             {
00034                 do
00035                 {
00036                     x = ((double)rand() / (double)RAND_MAX) * 2 - 1;
00037                     y = ((double)rand() / (double)RAND_MAX) * 2 - 1;
00038                     sqr = x*x + y*y;
00039                 }
00040                 while(sqr >=1.0 || sqr == 0);
00041                 double fac = sqrt(-2.0*log(sqr)/sqr);
00042 
00043                 x = (fac * x * mPosSigma) + mLastPos.translation.x;
00044                 y = (fac * y * mPosSigma) + mLastPos.translation.y;
00045             }
00046             while(x<0 || y<0 || x+mLastPos.size.x >= image.CW() || y+mLastPos.size.y >= image.CH());
00047 
00048             //sample search area at pos
00049             //if scale is used in the searcher, we should just send an image to the object representation.
00050             //since the representation might not use pixel data the representation is responsible for
00051             //interpreting the sample we provide it.
00052             Array::Pattern::PatSet(temp,&image, (int)x, (int)y, mLastPos.size.x, mLastPos.size.y, 0, 0);
00053 
00054             //get score
00055             score = mObject->Score(*temp,mLastPos);
00056 
00057             //if best
00058             if(score < bestScore)
00059             {
00060                 bestPos.x = x;
00061                 bestPos.y = y;
00062                 bestScore = score;
00063             }
00064         }
00065 
00066         //now search around the found position for the best fit, because not all neighbours are sampled
00067         int x,y;
00068         for(x=bestPos.x-3 ; x<=bestPos.x+3 ; x++)
00069         {
00070             for(y=bestPos.y-3 ; y<=bestPos.y+3 ; y++)
00071             {
00072                 if(x>=0 && y>=0 && x+mLastPos.size.x < image.CW() && y+mLastPos.size.y < image.CH())
00073                 {
00074                     Array::Pattern::PatSet(temp,&image, (int)x, (int)y, mLastPos.size.x, mLastPos.size.y, 0, 0);
00075                     score = mObject->Score(*temp,mLastPos);
00076                     if(score < bestScore)
00077                     {
00078                         bestPos.x = x;
00079                         bestPos.y = y;
00080                         bestScore = score;
00081                     }
00082                 }
00083             }
00084         }
00085         delete temp;
00086 
00087 
00088         mSpeed.translation.x = bestPos.x - mLastPos.translation.x;
00089         mSpeed.translation.y = bestPos.y - mLastPos.translation.y;
00090         mLastPos.translation = bestPos;
00091     }
00092 
00093     void Reset(Array::Array2dVec3Real64& image, ObjectRepresentation& object, const Position& pos)
00094     {
00095         SearcherBase::Reset(image, object, pos);
00096     }
00097 
00098 private:
00099     int mSampleSize;
00100     double mPosSigma; // in the future same for rotation and scale
00101     Position mSpeed;
00102 };
00103 
00104 } // namespace Tracking
00105 } // namespace Core
00106 } // namespace Impala
00107 
00108 #endif //Impala_Core_Tracking_SearcherAroundLastpos_h

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