Search window size in calcOpticalFlowPyrLK is interpreted differently than in cvCalcOpticalFlowPyrLK (Bug #344)
Description
The window size parameter in C++ calcOpticalFlowPyrLK is taken as the whole window size and divided by two to get the half window size while in cvCalcOpticalFlowPyrLK it is taken as the half window size and multiplied by two. The other pyramid optical flow algorithms do the same thing as cvCalcOpticalFlowPyrLK so only the calcOpticalFlowPyrLK code is different. If this is intended to match then they don't match and performance would vary. So is this a documentation issue or a bug that needs to be fixed in order to bring them both into agreement?
Related issues
duplicated by Bug #343: Search window size in calcOpticalFlowPyrLK is interpreted... | Cancelled |
Associated revisions
Merge pull request #344 from taka-no-me:improve_jpeg_encoder_errors
History
Updated by Vito Macchia over 14 years ago
I noticed some performance differences too, but I cannot say it is because of the window size.
I ported my code into full C++ but then I had to switch it to C for the optical flow part because of the different results: but to me also doubling the optical flow size in C++ brings different results than C. Much of the C code was adapted by the optical flow example under samples/c. It would be nice to translate it in C++.
Here is an example:
#if USE_C_LK //This variable decides wheter C or C++ has to be usedCvMat imgAmt = CvMat(imgA);
CvMat imgBmt = CvMat(imgB);
oFFoundFeatures=vector<uchar>(maxCorners,0);
opticalFlowFeatureError=vector<float>(maxCorners,0);
vector<CvPoint2D32f> _frameAFeatures;
for (int i=0;i<maxCorners;i++)
{
_frameAFeatures.push_back(cvPoint2D32f(frameAFeatures[i].x,frameAFeatures[i].y));
}
vector<CvPoint2D32f> _frameBFeatures=vector<CvPoint2D32f>(maxCorners,cvPoint2D32f(0,0));
CvPoint2D32f *fAfts=&_frameAFeaturesr0;
CvPoint2D32f *fBfts=&_frameBFeaturesr0;
char *offts=(char *)&oFFoundFeaturesr0;
float *errs = (float *)&opticalFlowFeatureErrorr0;
/* This is the window size to use to avoid the aperture problem (see slide "Optical Flow: Overview"). */
CvSize optical_flow_window = cvSize(3,3);
/* This termination criteria tells the algorithm to stop when it has either done 20 iterations or when
- epsilon is better than .3. You can play with these parameters for speed vs. accuracy but these values
- work pretty well in many situations.
*/
CvTermCriteria optical_flow_termination_criteria = cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, .3 );IplImage * pyramid1=cvCreateImage(cvSize(frame.cols,frame.rows),IPL_DEPTH_8U,1);
IplImage * pyramid2=cvCreateImage(cvSize(frame.cols,frame.rows),IPL_DEPTH_8U,1);
cvCalcOpticalFlowPyrLK(&imgAmt, &imgBmt, pyramid1, pyramid2, fAfts, fBfts, maxCorners, optical_flow_window, 5, offts, errs, optical_flow_termination_criteria, 0 );
//cvCalcOpticalFlowPyrLK(imgA, imgB, pyramid1, pyramid2, frameAFeatures, frameBFeatures, numOfFeatures, optical_flow_window, 5, oFFoundFeatures, optical_flow_feature_error, optical_flow_termination_criteria, 0 );for (int i=0;i<maxCorners;i++) {
frameBFeatures.push_back(Point2f(_frameBFeatures[i]));
}
#else
Size _opticalFlowWindw=Size(3,3);
TermCriteria _opticalFlowTerminationCriteria=TermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, .3 );
calcOpticalFlowPyrLK(imgA,imgB,frameAFeatures,frameBFeatures,oFFoundFeatures,opticalFlowFeatureError,_opticalFlowWindw,5,_opticalFlowTerminationCriteria,0.5,0);
#endif
I use self compiled OpenCV 2.1, Linux Ubuntu 9.10, g++ 4.4.1
Updated by anonymous - over 14 years ago
I also can confirm in quality and performance regression in c++ code
Updated by Vadim Pisarevsky over 13 years ago
finally, in the latest version from trunk cv::calcOpticalFlowPyrLK and cvCalcOpticalFlowPyrLK were unified. Performance of the C++ version has been greatly improved and the C function is now a wrapper on top of C++ function. Search window parameter is now interpreted in the same way in C and C++ versions, but differently from the old C version. It now specifies the whole size of the search window, not a quater of the search window as in C interface. Therefore, to get the same results, you need to pass a larger window size to optical flow: instead of (w,w), pass (w*2+1, w*2+1).
- Status changed from Open to Done
- (deleted custom field) set to fixed