61 #define MAX_CORNER_SUBPIXEL_ITERATIONS 100 
   73                 printf(
"error: image must be of type eGrayScale for CCornerSubpixel::refine\n");
 
   77         const int width = pImage->
width;
 
   78         const int height = pImage->
height;
 
   80         const int nWindowSize = 2 * nHalfWindowSize + 1;
 
   81         const int nWindowSizePlus2 = nWindowSize + 2;
 
   82         const int diff = width - nWindowSizePlus2;
 
   84         float grayValues[1024];
 
   85         float *pGrayValues = nWindowSizePlus2 <= 32 ? grayValues : 
new float[nWindowSizePlus2 * nWindowSizePlus2];
 
   88         const float ux = point.
x;
 
   89         const float uy = point.
y;
 
   91         const unsigned char *pixels = pImage->
pixels;
 
   93         Vec2d v = { 0.0f, 0.0f };
 
   95         for (
int k = 0; k < nMaxIterations; k++)
 
   97                 const int xb = int(floorf(ux + v.
x));
 
   98                 const int yb = int(floorf(uy + v.
y));
 
  100                 if (xb - nHalfWindowSize < 1 || xb + nHalfWindowSize + 3 >= width || yb - nHalfWindowSize < 1 || yb + nHalfWindowSize + 3 >= height)
 
  103                 const float dx = ux + v.
x - float(xb);
 
  104                 const float dy = uy + v.
y - float(yb);
 
  106                 const float f00 = (1.0f - dx) * (1.0f - dy);
 
  107                 const float f10 = dx * (1.0f - dy);
 
  108                 const float f01 = (1.0f - dx) * dy;
 
  109                 const float f11 = dx * dy;
 
  111                 int j, offset, offset2;
 
  113                 for (j = nWindowSizePlus2, offset = (yb - nHalfWindowSize - 1) * width + xb - nHalfWindowSize - 1, offset2 = 0; j; j--, offset += diff)
 
  114                         for (
int jj = nWindowSizePlus2; jj; jj--, offset++, offset2++)
 
  115                                 pGrayValues[offset2] = f00 * pixels[offset] + f10 * pixels[offset + 1] + f01 * pixels[offset + width] + f11 * pixels[offset + width + 1];
 
  117                 float gxx_sum = 0.0f, gxy_sum = 0.0f, gyy_sum = 0.0f;
 
  118                 float bx = 0.0f, by = 0.0f;
 
  120                 for (j = 0, offset = nWindowSizePlus2 + 1; j < nWindowSize; j++, offset += 2)
 
  121                         for (
int jj = 0; jj < nWindowSize; jj++, offset++)
 
  123                                 const float ix = pGrayValues[offset + 1] - pGrayValues[offset - 1];
 
  124                                 const float iy = pGrayValues[offset + nWindowSizePlus2] - pGrayValues[offset - nWindowSizePlus2];
 
  126                                 const float gxx = ix * ix;
 
  127                                 const float gyy = iy * iy;
 
  128                                 const float gxy = ix * iy;
 
  134                                 bx += gxx * float(jj - nHalfWindowSize) + gxy * float(j - nHalfWindowSize);
 
  135                                 by += gxy * float(jj - nHalfWindowSize) + gyy * float(j - nHalfWindowSize);
 
  138                 if (fabsf(gxx_sum * gyy_sum - gxy_sum * gxy_sum) <= FLT_EPSILON)
 
  140                         if (nWindowSizePlus2 > 32)
 
  141                                 delete [] pGrayValues;
 
  148                 const Mat2d G = { gxx_sum, gxy_sum, gxy_sum, gyy_sum };
 
  152                 const Vec2d b = { bx, by };
 
  163         if (nWindowSizePlus2 > 32)
 
  164                 delete [] pGrayValues;
 
Data structure for the representation of a 2D vector. 
float SquaredLength(const Vec2d &vec)
Data structure for the representation of a 2x2 matrix. 
void Invert(const Mat2d &matrix, Mat2d &result)
ImageType type
The type of the image. 
int width
The width of the image in pixels. 
int height
The height of the image in pixels. 
bool Refine(const CByteImage *pImage, const Vec2d &point, Vec2d &resultPoint, int nHalfWindowSize=2, int nMaxIterations=100)
unsigned char * pixels
The pointer to the the pixels. 
void MulMatVec(const Mat2d &matrix, const Vec2d &vec, Vec2d &result)
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
void SetVec(Vec2d &vec, float x, float y)
void AddToVec(Vec2d &vec, const Vec2d &vectorToAdd)