Saturday, January 08, 2005

OpenCV: Optical flow function

p>Compute Image Flow (Lucas-Kanade Method)

void cvCalcOpticalFlowLK( const CvArr* imgA, const CvArr* imgB, CvSize winSize, CvArr* velx, CvArr* vely );

cvCalcOpticalFlowLK( imgA, imgB, cvSize(15,15), velX, velY);

winSize can only be odd value and it is up to 15.
- cvCalcOpticalFlowLK returns two velocity matrices velx and vely. These matrices give the displacement of every pixel in the first image.
- Use the velocity matrices to calculate the locations of the good features in the second image.
- Mark the calculated locations of the good features in the second image.
- For each tracked feature point, use the same color marker for both images. This helps us assess whether the feature points are correctly tracked.

Different combinations of parameter values for cvGoodFeaturesToTrack and cvCalcOpticalFlowLK to obtain the best result. The function cvGoodFeaturesToTrack requires an extra NULL argument. This is not documented in the OpenCV Reference Manual.
This function requires a pointer to an array of CvPoint2D32f for storing the corners detected. You should prepare the array before you call the function, e.g.,
#define MAX_NUMBER_OF_CORNERS 200
CvPoint2D32f corners[MAX_NUMBER_OF_CORNERS];
int cornerCount;
...
cornerCount = MAX_NUMBER_OF_CORNERS;
cvGoodFeaturesToTrack (image, eigen, temp, corners, &cornerCount, qualityLevel, minDistance, NULL);

The variable cornerCount is set to the maximum number before calling the function. It will be changed by the function to the actual number of corners detected. The data type CvPoint2D32f contains two fields x and y, e.g., corners[i].x, corners[i].y.

No comments:

Post a Comment