Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup & remove shared vars #50

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/libopentld/mftracker/FBTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ int fbtrack(IplImage *imgI, IplImage *imgJ, float *bb, float *bbnew,
//getFilledBBPoints(bb, numM, numN, 5, &ptTracked);
memcpy(ptTracked, pt, sizeof(float) * sizePointsArray);

initImgs();
trackLK(imgI, imgJ, pt, nPoints, ptTracked, nPoints, level, fb, ncc, status);
initImgs();
// char* status = *statusP;
nlkPoints = 0;

Expand Down
46 changes: 7 additions & 39 deletions src/libopentld/mftracker/Lk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ const double N_A_N = -1.0;
/**
* Size of the search window of each pyramid level in cvCalcOpticalFlowPyrLK.
*/
int win_size_lk = 4;
CvPoint2D32f *points[3] = { 0, 0, 0 };
static IplImage **PYR = 0;
const int win_size_lk = 4;


/**
* Calculates euclidean distance between the point pairs.
Expand Down Expand Up @@ -109,34 +108,8 @@ void normCrossCorrelation(IplImage *imgI, IplImage *imgJ,
cvReleaseImage(&res);
}

/**
* Needed before start of trackLK and at the end of the program for cleanup.
* Handles PYR(Pyramid cache) variable.
*/
void initImgs()
{
if(PYR != 0)
{
int i;

for(i = 0; i < MAX_IMG; i++)
{
cvReleaseImage(&(PYR[i]));
PYR[i] = 0;
}

free(PYR);
PYR = 0;
//printf("LK: deallocated\n");
}

PYR = (IplImage **) calloc(MAX_IMG, sizeof(IplImage *));
//printf("LK: initialized\n");
}

/**
* Tracks Points from 1.Image to 2.Image.
* Need initImgs before start and at the end of the program for cleanup.
*
* @param imgI previous Image source. (isn't changed)
* @param imgJ actual Image target. (isn't changed)
Expand Down Expand Up @@ -165,9 +138,9 @@ int trackLK(IplImage *imgI, IplImage *imgJ, float ptsI[], int nPtsI,
//TODO: watch NaN cases
//double nan = std::numeric_limits<double>::quiet_NaN();
//double inf = std::numeric_limits<double>::infinity();

CvPoint2D32f *points[3] = { 0, 0, 0 };
// tracking
int I, J, winsize_ncc;
int winsize_ncc;
CvSize pyr_sz;
int i;

Expand All @@ -177,15 +150,10 @@ int trackLK(IplImage *imgI, IplImage *imgJ, float ptsI[], int nPtsI,
level = 5;
}

I = 0;
J = 1;
winsize_ncc = 10;

//NOTE: initImgs() must be used correctly or memleak will follow.
pyr_sz = cvSize(imgI->width + 8, imgI->height / 3);
PYR[I] = cvCreateImage(pyr_sz, IPL_DEPTH_32F, 1);
PYR[J] = cvCreateImage(pyr_sz, IPL_DEPTH_32F, 1);


// Points
if(nPtsJ != nPtsI)
{
Expand All @@ -210,13 +178,13 @@ int trackLK(IplImage *imgI, IplImage *imgJ, float ptsI[], int nPtsI,
}

//lucas kanade track
cvCalcOpticalFlowPyrLK(imgI, imgJ, PYR[I], PYR[J], points[0], points[1],
cvCalcOpticalFlowPyrLK(imgI, imgJ, 0, 0, points[0], points[1],
nPtsI, cvSize(win_size_lk, win_size_lk), level, status, 0, cvTermCriteria(
CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03),
CV_LKFLOW_INITIAL_GUESSES);

//backtrack
cvCalcOpticalFlowPyrLK(imgJ, imgI, PYR[J], PYR[I], points[1], points[2],
cvCalcOpticalFlowPyrLK(imgJ, imgI, 0, 0, points[1], points[2],
nPtsI, cvSize(win_size_lk, win_size_lk), level, statusBacktrack, 0, cvTermCriteria(
CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.03),
CV_LKFLOW_INITIAL_GUESSES | CV_LKFLOW_PYR_A_READY | CV_LKFLOW_PYR_B_READY);
Expand Down
1 change: 0 additions & 1 deletion src/libopentld/mftracker/Lk.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
/**
* Need before start of trackLK and at the end of the program for cleanup.
*/
void initImgs();
int trackLK(IplImage *imgI, IplImage *imgJ, float ptsI[], int nPtsI,
float ptsJ[], int nPtsJ, int level, float *fbOut, float *nccOut,
char *statusOut);
Expand Down