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.

Problums with VLIB's Lucas Kanade feature tracking on DM6437

Hi all,

I'm trying to implement VLIB's functions (Lucas Kanade Features Tracking) for a moving object tracking on DM6437.

My code looks like this.

static short  BufGradX[WIDTH*HEIGHT];
static short  BufGradY[WIDTH*HEIGHT];
static short  BufMag[WIDTH*HEIGHT];
static short  BufGradXOld[WIDTH*HEIGHT];
static short  BufGradYOld[WIDTH*HEIGHT];
static short  HrScore [WIDTH*HEIGHT];
static unsigned char BufOut[WIDTH*HEIGHT];
static unsigned char nonMaxSuppr [WIDTH*HEIGHT];
static unsigned char scratchHS[WIDTH*(HEIGHT+96)];
static short sensHS = 1310;
static short thold = 25;

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

void doLucasKanade(unsigned char *pCurImage, unsigned char *pPrevImage, int width, int height)
{
    int           i, j;
    int           nFeatures = 0;
    short         *pGx     = &BufGradX[0];
    short         *pGy     = &BufGradY[0];
    short         *pMag    = &BufMag[0];
    unsigned char *pBufIn  = pCurImage;
    unsigned char *pBufOut = &pBufOut[0];
    unsigned char *pScratch;

    memset(&BufGradX[0],    0, sizeof(BufGradX));
    memset(&BufGradY[0],    0, sizeof(BufGradY));
    memset(&BufMag[0],      0, sizeof(BufMag));
    memset(&BufOut[0],      0, sizeof(BufOut));
    memset(&HrScore[0],     0, sizeof(HrScore));
    memset(&nonMaxSuppr[0], 0, sizeof(nonMaxSuppr));

    memset(&fpY[0], 0, sizeof(fpY));
    memset(&fpX[0], 0, sizeof(fpX));
    memset(&fpnY[0], 0, sizeof(fpnY));
    memset(&fpnX[0], 0, sizeof(fpnX));
    memset(&outX[0], 0, sizeof(outX));
    memset(&outY[0], 0, sizeof(outY));

    VLIB_xyGradientsAndMagnitude(pBufIn+width+1, pGx+width*2+2, pGy+width*2+2, pMag+width*2+2, width, height-4);
    VLIB_harrisScore_7x7(pGx, pGy, width, height, &HrScore[0], 1310, scratchHS);
    VLIB_nonMaxSuppress_7x7_S16(&HrScore[0], width, height, thold, &nonMaxSuppr[0]);
    for (i=0; i<height; i++)
    {
        for (j=0; j<width; j++)
        {
            if (nonMaxSuppr[i*height+j] == 255)
            {
                fpY[nFeatures]  = i << 4;
                fpX[nFeatures]  = j << 4;
                fpnY[nFeatures] = fpY[nFeatures];
                fpnX[nFeatures] = fpX[nFeatures];
                nFeatures++;
            }
        }
    }
    VLIB_trackFeaturesLucasKanade_7x7(pPrevImage, pCurImage, &BufGradXOld[0], (short* restrict)&BufGradYOld[0],
                     width, height, nFeatures, &fpX[0], &fpY[0], &fpnX[0], &fpnY[0], 10, scratchLK);

    for (i=0; i<nFeatures; i++)
    {
        if ((fpnX[i] >= 0 ) && (fpnY[i] >= 0))
        {
            outX[i] = fpnX[i]>>4 - fpX[i]>>4;
            outY[i] = fpnY[i]>>4 - fpY[i]>>4;
        }
        else
        {
            outX[i] = 0;
            outY[i] = 0;
        }
    }

    memcpy(pPrevImage,  pCurImage, width*height);
    memcpy(BufGradXOld, BufGradX,  width*height*sizeof(short));
    memcpy(BufGradYOld, BufGradY,  width*height*sizeof(short));
}

When I deal with LK function, what is the coordinates of a moving object?

In my opinion, the coordinates of the object is considered to be in pfnX[] and pfnY[]. But I found something went wrong. The result showed me that it uses only half of the entire screen or displays tracking results on only half of the monitor.

How can I indicate the right coordinates?

This results were as follows:

fpnX[] = {4800, 5278, 5776, 94, 111, 1345, 1825, 2318, 4365, 5857, 914, 2406, 3824, 4191, 4384, 5008, 368, .... , 3552, 3568}

fpnY[] = {1824, 1822, 1824, 1836, 1837, 1838, 1838, 1838, 1841, 1839, 1857, 1855, 1857, 1855, 1855, 1857, 1873, .... , 3440, 1808, 1824, 1824}

I calculate fpnX[i]>>4 and fpnY[i]>>4 to determine the coordinates. (pfnX and pfnY types are SQ11.4)

As a result, x-coordinate appears in a random position and only y-coordinate position appears at lower end of the image.

What should I do in order to find the exact location of a moving object?

 Thanks & Best Regards.