63 #define KLT_ITERATIONS 20 82 for (i = 0; i <= nLevels; i++)
122 printf(
"error: image must be of type eGrayScale for CKLTTracker::Track\n");
148 const int nWindowSizePlus2 = nWindowSize + 2;
152 float *IX =
new float[nWindowSizePlus2 * nWindowSizePlus2];
153 float *IY =
new float[nWindowSizePlus2 * nWindowSizePlus2];
154 float *pGrayValues =
new float[nWindowSizePlus2 * nWindowSizePlus2];
157 for (i = 0; i < nPoints; i++)
159 const float ux = pPoints[i].
x;
160 const float uy = pPoints[i].
y;
162 if (ux < 0.0f && uy < 0.0f)
178 const int px = int(floorf(px_));
179 const int py = int(floorf(py_));
181 if (px - m_nHalfWindowSize < 1 || px + m_nHalfWindowSize + 3 > w || py - m_nHalfWindowSize < 1 || py + m_nHalfWindowSize + 3 > h)
190 const int diff = w - nWindowSizePlus2;
192 const float dx = px_ - floorf(px_);
193 const float dy = py_ - floorf(py_);
195 const float f00 = (1.0f - dx) * (1.0f - dy);
196 const float f10 = dx * (1.0f - dy);
197 const float f01 = (1.0f - dx) * dy;
198 const float f11 = dx * dy;
201 for (
int jj = nWindowSizePlus2; jj; jj--, offset++, offset2++)
202 pGrayValues[offset2] = f00 * pixelsI[offset] + f10 * pixelsI[offset + 1] + f01 * pixelsI[offset + w] + f11 * pixelsI[offset + w + 1];
205 float gxx = 0.0f, gxy = 0.0f, gyy = 0.0f;
207 for (
int j = nWindowSize,
offset = nWindowSizePlus2 + 1; j; j--,
offset += 2)
208 for (
int jj = nWindowSize; jj; jj--, offset++)
210 const float ix = pGrayValues[offset + 1] - pGrayValues[offset - 1];
211 const float iy = pGrayValues[offset + nWindowSizePlus2] - pGrayValues[offset - nWindowSizePlus2];
223 if (fabsf(gxx * gyy - gxy * gxy) > FLT_EPSILON)
225 const Mat2d G = { gxx, gxy, gxy, gyy };
233 const float dxJ = g.
x + v.
x;
234 const float dyJ = g.
y + v.
y;
236 const int xb = int(floorf(px_ + dxJ));
237 const int yb = int(floorf(py_ + dyJ));
239 if (xb - m_nHalfWindowSize < 1 || xb + m_nHalfWindowSize + 3 >= w || yb - m_nHalfWindowSize < 1 || yb + m_nHalfWindowSize + 3 >= h)
242 float bx = 0.0f,
by = 0.0f;
245 const int diff = w - nWindowSize;
247 const float dx = px_ + dxJ - floorf(px_ + dxJ);
248 const float dy = py_ + dyJ - floorf(py_ + dyJ);
250 const float f00 = (1.0f - dx) * (1.0f - dy);
251 const float f10 = dx * (1.0f - dy);
252 const float f01 = (1.0f - dx) * dy;
253 const float f11 = dx * dy;
256 for (
int jj = nWindowSize; jj; jj--, offset++, offset2++)
258 const float dI = pGrayValues[offset2] - (f00 * pixelsJ[
offset] + f10 * pixelsJ[offset + 1] + f01 * pixelsJ[offset +
w] + f11 * pixelsJ[offset + w + 1]);
260 bx += IX[offset2] * dI;
261 by += IY[offset2] * dI;
283 g.
x = 2.0f * (g.
x + d.
x);
284 g.
y = 2.0f * (g.
y + d.
y);
290 const float x = ux + d.
x;
291 const float y = uy + d.
y;
293 const int x_ = int(floorf(x));
294 const int y_ = int(floorf(y));
310 delete [] pGrayValues;
int width
The width of the image in pixels.
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...
void MulVecScalar(const Vec2d &vec, float scalar, Vec2d &result)
CKLTTracker(int width, int height, int nLevels, int nHalfWindowSize)
unsigned char * pixels
The pointer to the the pixels.
CByteImage ** m_ppPyramidI
const int m_nHalfWindowSize
Data structure for the representation of a 2x2 matrix.
bool Track(const CByteImage *pImage, const Vec2d *pPoints, int nPoints, Vec2d *pResultPoints)
bool CopyImage(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bUseSameSize=false)
Copies one CByteImage to another.
int height
The height of the image in pixels.
void Invert(const Mat2d &matrix, Mat2d &result)
GLenum GLsizei GLsizei height
void AddToVec(Vec2d &vec, const Vec2d &vectorToAdd)
ImageType type
The type of the image.
Data structure for the representation of a 2D vector.
CByteImage ** m_ppPyramidJ
void SetVec(Vec2d &vec, float x, float y)
GLubyte GLubyte GLubyte GLubyte w
float SquaredLength(const Vec2d &vec)
void MulMatVec(const Mat2d &matrix, const Vec2d &vec, Vec2d &result)
bool Resize(const CByteImage *pInputImage, CByteImage *pOutputImage, const MyRegion *pROI=0, bool bInterpolation=true)
Resizes a CByteImage and writes the result to a CByteImage.