SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
MiniPatch.cpp
Go to the documentation of this file.
1 // Copyright 2008 Isis Innovation Limited
2 #include "MiniPatch.h"
3 using namespace CVD;
4 using namespace std;
5 
6 // Scoring function
8 {
9  if(!im.in_image_with_border(ir, mnHalfPatchSize))
10  return mnMaxSSD + 1;
11  ImageRef irImgBase = ir - ImageRef(mnHalfPatchSize, mnHalfPatchSize);
12  int nRows = mimOrigPatch.size().y;
13  int nCols = mimOrigPatch.size().x;
14  byte *imagepointer;
15  byte *templatepointer;
16  int nDiff;
17  int nSumSqDiff = 0;
18  for(int nRow = 0; nRow < nRows; nRow++)
19  {
20  imagepointer = &im[irImgBase + ImageRef(0,nRow)];
21  templatepointer = &mimOrigPatch[ImageRef(0,nRow)];
22  for(int nCol = 0; nCol < nCols; nCol++)
23  {
24  nDiff = imagepointer[nCol] - templatepointer[nCol];
25  nSumSqDiff += nDiff * nDiff;
26  };
27  };
28  return nSumSqDiff;
29 }
30 
31 // Find a patch by searching at FAST corners in an input image
32 // If available, a row-corner LUT is used to speed up search through the
33 // FAST corners
36  int nRange,
37  vector<ImageRef> &vCorners,
38  std::vector<int> *pvRowLUT)
39 {
40  ImageRef irCenter = irPos;
41  ImageRef irBest;
42  int nBestSSD = mnMaxSSD + 1;
43  ImageRef irBBoxTL = irPos - ImageRef(nRange, nRange);
44  ImageRef irBBoxBR = irPos + ImageRef(nRange, nRange);
45  vector<ImageRef>::iterator i;
46  if(!pvRowLUT)
47  {
48  for(i = vCorners.begin(); i!=vCorners.end(); i++)
49  if(i->y >= irBBoxTL.y) break;
50  }
51  else
52  {
53  int nTopRow = irBBoxTL.y;
54  if(nTopRow < 0)
55  nTopRow = 0;
56  if(nTopRow >= (int) pvRowLUT->size())
57  nTopRow = (int) pvRowLUT->size() - 1;
58  i = vCorners.begin() + (*pvRowLUT)[nTopRow];
59  }
60 
61  for(; i!=vCorners.end(); i++)
62  {
63  if(i->x < irBBoxTL.x || i->x > irBBoxBR.x)
64  continue;
65  if(i->y > irBBoxBR.y)
66  break;
67  int nSSD = SSDAtPoint(im, *i);
68 
69  if(nSSD < nBestSSD)
70  {
71  irBest = *i;
72  nBestSSD = nSSD;
73  }
74  }
75  if(nBestSSD < mnMaxSSD)
76  {
77  irPos = irBest;
78  return true;
79  }
80  else
81  return false;
82 }
83 
84 // Define the patch from an input image
86 {
87  assert(im.in_image_with_border(irPos, mnHalfPatchSize));
88  CVD::ImageRef irPatchSize( 2 * mnHalfPatchSize + 1 , 2 * mnHalfPatchSize + 1);
89  mimOrigPatch.resize(irPatchSize);
90  copy(im, mimOrigPatch, mimOrigPatch.size(), irPos - mimOrigPatch.size() / 2);
91 }
92 
93 // Static members
95 int MiniPatch::mnRange = 10;
96 int MiniPatch::mnMaxSSD = 9999;
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
int y
The y co-ordinate.
Definition: image_ref.h:180
int x
The x co-ordinate.
Definition: image_ref.h:179
void SampleFromImage(CVD::ImageRef irPos, CVD::BasicImage< CVD::byte > &im)
Definition: MiniPatch.cpp:85
bool FindPatch(CVD::ImageRef &irPos, CVD::BasicImage< CVD::byte > &im, int nRange, std::vector< CVD::ImageRef > &vCorners, std::vector< int > *pvRowLUT=NULL)
Definition: MiniPatch.cpp:34
Definition: abs.h:24
static int mnMaxSSD
Definition: MiniPatch.h:34
void copy(const BasicImage< S > &in, BasicImage< T > &out, ImageRef size=ImageRef(-1,-1), ImageRef begin=ImageRef(), ImageRef dst=ImageRef())
Definition: utility.h:26
ImageRef size() const
What is the size of this image?
Definition: image.h:370
bool in_image_with_border(const ImageRef &ir, int border) const
Definition: image.h:271
static int mnRange
Definition: MiniPatch.h:33
ImageRef ir(const TooN::Vector< 2 > &v)
unsigned char byte
Definition: byte.h:28
int SSDAtPoint(CVD::BasicImage< CVD::byte > &im, const CVD::ImageRef &ir)
Definition: MiniPatch.cpp:7
static int mnHalfPatchSize
Definition: MiniPatch.h:32