This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Trouble with Lukas_Kanade Tracker

I try to create program for feature tracking. I took the idea from the picture:

My code of program is:


#include <VLIB_prototypes.h>

#define WIDTH 720
#define HEIGHT 576
#define PITCH 1440
#define W ((WIDTH - 4)/2)
#define H ((HEIGHT - 3)/2)

//-----------------------------------------------------------------------------------------------------------------------
// Gaussian Pyramid
//-----------------------------------------------------------------------------------------------------------------------
static unsigned char GsPyramidOld[W*H]; // Gaussian Pyramid local buffer of previous Luma
static unsigned char GsPyramid [W*H]; // Gaussian Pyramid local buffer of current Luma
static unsigned short GsPBuffer [(WIDTH - 4)*HEIGHT]; // Temp buffer for calculate Gaussian Pyramid

//-----------------------------------------------------------------------------------------------------------------------
// Gradient Pyramid
//-----------------------------------------------------------------------------------------------------------------------
static unsigned char GrVPyramidOld[W*H]; // Vertical Gradient Pyramid local buffer of previous Luma
static unsigned char GrHPyramidOld[W*H]; // Horizontal Gradient Pyramid local buffer of previous Luma
static unsigned char GrVPyramid [W*H]; // Vertical Gradient Pyramid local buffer of current Luma
static unsigned char GrHPyramid [W*H]; // Horizontal Gradient Pyramid local buffer of current Luma
static short GrPBuffer [(WIDTH - 4)*HEIGHT]; // Temp buffer for calculate Gradient Pyramid

static signed short GrVPyramidOldShort [W*H]; // Vertical Gradient Pyramid local buffer of previous Luma
static signed short GrHPyramidOldShort [W*H]; // Horizontal Gradient Pyramid local buffer of previous Luma
static signed short GrVPyramidShort [W*H]; // Vertical Gradient Pyramid local buffer of current Luma
static signed short GrHPyramidShort [W*H]; // Horizontal Gradient Pyramid local buffer of current Luma

//-----------------------------------------------------------------------------------------------------------------------
// Harris Score and Non-Maximum Suppression
//-----------------------------------------------------------------------------------------------------------------------
static short HrScore [W*H]; // Harris (cornerness) score
static unsigned char scratchHS [W*(H + 96)]; // Scratch buffer for Harris Score
static short sensHS = 1310; // Sensitivity parameter 0.04*2^15 => 1310

static unsigned char nonMaxSuppr [W*H]; // Binary output indicating peaks
static short thold = 25<<10; // Minimum threshold for peaks

//-----------------------------------------------------------------------------------------------------------------------
// Lucas - Kanade Track Feature
//-----------------------------------------------------------------------------------------------------------------------

short fpX[W*H], // Coordinate X of previous points
fpY[W*H], // Coordinate Y of previous points
fpnX[W*H], // Coordinate X of current points
fpnY[W*H]; // Coordinate Y of current points
static unsigned char scratchLK [/*POINTS*/384]; // Scratch buffer for Lucas-Kanade

//-----------------------------------------------------------------------------------------------------------------------
static char isInit = 0; // Indicating initial previous Luma
//-----------------------------------------------------------------------------------------------------------------------

// function prototype
//-----------------------------------------------------------------------------------------------------------------------
void trackLK( unsigned char* curLuma );
//=======================================================================================================================
void trackLK( unsigned char* curLuma)
{
unsigned char nFeatures = 0; // counter points of Harris Score :nFeatures
unsigned int i, h;

if(!isInit)
{
dprintfLK1(WIDTH);
dprintfLK1(HEIGHT);
dprintfLK1(PITCH);
dprintfLK1(H);
dprintfLK1(W);


VLIB_gauss5x5PyramidKernel_8(
curLuma, // input 8b data VLIB_gauss5x5PyramidKernel_8
GsPBuffer, // tempbuf
(WIDTH - 4), // width must be divisible by 8
(PITCH / 2-4), // pitch
HEIGHT, // height must be > 4
GsPyramidOld); // output 8b data out image size:(w - 4)/2 x (h - 3)/2


VLIB_gradientH5x5PyramidKernel_8(
curLuma, // input 8b data
GrPBuffer, // tempbuf
WIDTH - 4, // width must be divisible by 8
PITCH / 2-4, // pitch
HEIGHT, // height must be > 4
GrHPyramidOld); // output 8b data out image size: (w-4)/2 x (h-3)/2

VLIB_gradientV5x5PyramidKernel_8(
curLuma, // input 8b data
GrPBuffer, // tempbuf
WIDTH - 4, // width must be divisible by 8
PITCH / 2-4, // pitch
HEIGHT, // height must be > 4
GrVPyramidOld); // 8b output data out image size: (w-4)/2 x (h-3)/2
isInit = 1;
}
else
{
VLIB_gauss5x5PyramidKernel_8(
curLuma, // input 8b data VLIB_gauss5x5PyramidKernel_8
GsPBuffer, // tempbuf
(WIDTH - 4), // width must be divisible by 8
(PITCH / 2)-4, // pitch
HEIGHT, // height must be > 4
GsPyramid); // output 8b data out image size:(w - 4)/2 x (h - 3)/2

VLIB_gradientH5x5PyramidKernel_8(
curLuma, // input 8b data
GrPBuffer, // tempbuf
WIDTH - 4, // width must be divisible by 8
PITCH / 2-4, // pitch
HEIGHT, // height must be >4
GrHPyramid); // output 8b data out image size: (w-4)/2 x (h-3)/2

VLIB_gradientV5x5PyramidKernel_8(
curLuma, // input 8b data
GrPBuffer, // tempbuf
WIDTH - 4, // width must be divisible by 8
PITCH / 2-4, // pitch
HEIGHT, // height must be >4
GrVPyramid); // 8b output data out image size: (w-4)/2 x (h-3)/2

VLIB_harrisScore_7x7(
(short*)GrHPyramid, // xGrad of luma
(short*)GrVPyramid, // yGrad of luma
W, // width W = (w-4)/2
H, // height H = (h-3)/2
&HrScore[0], // Harris score output (w-4)/2 x (h-3)/2
sensHS, // sensitiv 1310
scratchHS); // scratchbuf

for(i = 0; i < W*H; i++)
{
HrScore[i] = HrScore[i]>>10;
}

VLIB_nonMaxSuppress_7x7_S16(
&HrScore[0], // input image
W, // width W = (w-4)/2
H, // height H = (h-3)/2
thold, // threshold = 24
nonMaxSuppr); // output data (w-4)/2 x (h-3)/2

for(i = 0; i < W*H; i++)
{
if(nonMaxSuppr[i]==255)
{
h = i/(W);
fpY[nFeatures] = h<<4;
fpX[nFeatures] = (i - (W)*(h))<<4;
nFeatures++;
}
}
if(nFeatures!=0)
{

for(i = 0; i < nFeatures; i++)
{
fpnX[i]=fpX[i];
fpnY[i]=fpY[i];
}

VLIB_trackFeaturesLucasKanade_7x7(
&GsPyramidOld[0], // image at t - 1
&GsPyramid[0], // image at t
(short* restrict)GrHPyramidOld, // hor gradient of image at t
(short* restrict)GrVPyramidOld, // vert gradient of image at t
W, // width
H, // height
nFeatures, // number of features
&fpX[0], // X[]
&fpY[0], // Y[]
&fpnX[0], // new X[]
&fpnY[0], // new Y[]
6, // number of iterations
scratchLK); // scratch buffer
}
memcpy(GsPyramidOld,GsPyramid,W*H);
memcpy(GrHPyramidOld,GrHPyramid,W*H);
memcpy(GrVPyramidOld,GrVPyramid,W*H);
}
}

Now the problem is when I process the GsPyramidOld(this is image at t - 1) some of the value in fpnX[] and fpnY[] array become negative after calling VLIB_trackFeaturesLucasKanade_7x7 function.

My question is why these values may be negative ? How to overcome this problem ?

Thanks & Regards,
Albert Zeman.