MiniPatch.cc
Go to the documentation of this file.
00001 // Copyright 2008 Isis Innovation Limited
00002 #include "MiniPatch.h"
00003 using namespace CVD;
00004 using namespace std;
00005 
00006 // Scoring function
00007 inline int MiniPatch::SSDAtPoint(CVD::BasicImage<CVD::byte> &im, const CVD::ImageRef &ir)
00008 {
00009   if(!im.in_image_with_border(ir, mnHalfPatchSize))
00010     return mnMaxSSD + 1;
00011   ImageRef irImgBase = ir - ImageRef(mnHalfPatchSize, mnHalfPatchSize);
00012   int nRows = mimOrigPatch.size().y;
00013   int nCols = mimOrigPatch.size().x;
00014   byte *imagepointer;
00015   byte *templatepointer;
00016   int nDiff;
00017   int nSumSqDiff = 0;
00018   for(int nRow = 0; nRow < nRows; nRow++)
00019     {
00020       imagepointer = &im[irImgBase + ImageRef(0,nRow)];
00021       templatepointer = &mimOrigPatch[ImageRef(0,nRow)];
00022       for(int nCol = 0; nCol < nCols; nCol++)
00023         {
00024           nDiff = imagepointer[nCol] - templatepointer[nCol];
00025           nSumSqDiff += nDiff * nDiff;
00026         };
00027     };
00028   return nSumSqDiff;
00029 }
00030 
00031 // Find a patch by searching at FAST corners in an input image
00032 // If available, a row-corner LUT is used to speed up search through the
00033 // FAST corners
00034 bool MiniPatch::FindPatch(CVD::ImageRef &irPos,
00035                           CVD::BasicImage<CVD::byte> &im,
00036                           int nRange,
00037                           vector<ImageRef> &vCorners,
00038                           std::vector<int> *pvRowLUT)
00039 {
00040   ImageRef irBest;
00041   int nBestSSD = mnMaxSSD + 1;
00042   ImageRef irBBoxTL = irPos - ImageRef(nRange, nRange);
00043   ImageRef irBBoxBR = irPos + ImageRef(nRange, nRange);
00044   vector<ImageRef>::iterator i;
00045   if(!pvRowLUT)
00046     {
00047       for(i = vCorners.begin(); i!=vCorners.end(); i++)
00048         if(i->y >= irBBoxTL.y) break;
00049     }
00050   else
00051     {
00052       int nTopRow = irBBoxTL.y;
00053       if(nTopRow < 0)
00054         nTopRow = 0;
00055       if(nTopRow >= (int) pvRowLUT->size())
00056         nTopRow = (int) pvRowLUT->size() - 1;
00057       i = vCorners.begin() + (*pvRowLUT)[nTopRow];
00058     }
00059 
00060   for(; i!=vCorners.end(); i++)
00061     {
00062       if(i->x < irBBoxTL.x  || i->x > irBBoxBR.x)
00063         continue;
00064       if(i->y > irBBoxBR.y)
00065         break;
00066       int nSSD = SSDAtPoint(im, *i);
00067 
00068       if(nSSD < nBestSSD)
00069         {
00070           irBest = *i;
00071           nBestSSD = nSSD;
00072         }
00073     }
00074   if(nBestSSD < mnMaxSSD)
00075     {
00076       irPos = irBest;
00077       return true;
00078     }
00079   else
00080     return false;
00081 }
00082 
00083 // Define the patch from an input image
00084 void MiniPatch::SampleFromImage(ImageRef irPos, BasicImage<byte> &im)
00085 {
00086   assert(im.in_image_with_border(irPos, mnHalfPatchSize));
00087   CVD::ImageRef irPatchSize( 2 * mnHalfPatchSize + 1 , 2 * mnHalfPatchSize + 1);
00088   mimOrigPatch.resize(irPatchSize);
00089   copy(im, mimOrigPatch, mimOrigPatch.size(), irPos - mimOrigPatch.size() / 2);
00090 }
00091 
00092 // Static members
00093 int MiniPatch::mnHalfPatchSize = 4;
00094 int MiniPatch::mnRange = 10;
00095 int MiniPatch::mnMaxSSD = 9999;
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 


uga_tum_ardrone
Author(s):
autogenerated on Sat Jun 8 2019 20:30:11