Updated by Andrey Kamaev almost 13 years ago

Hello all,

First of all, thanks a lot for your great job. I am using OpenCV for quite a bit now, and it is more and more amazing. Thank you again.

I was eager to try the new optical flows functions implemented on gpu. The goal was to compare the performances between OpenCV Alone functions, OpenCV compiled with CUDA functions (here i am working with CUDA 4.1) and the same functions implemented with IPP.
That is why i tried to test @gpu::PyrLKOpticalFlow::sparse@. gpu::PyrLKOpticalFlow::sparse.

For one of my current problem, i am using a sparse optical flow with a window size between 80 and 120 pixels.
With OpenCV Alone sparse LK Optical Flow, no problems, but the use of the gpu function makes my program crash.

By looking at the sources (@pyrlk.cpp@, (pyrlk.cpp, ln 162) there is the following assertion :
@CV_Assert(patch.x CV_Assert(patch.x > 0 && patch.x < 6 && patch.y > 0 && patch.y < 6);@ 6);
with
@patch.x patch.x = (winSize.width * cn + block.x - 1) / block.x@ block.x with @block.x block.x = 32@ 32 when @winSize.width winSize.width * cn > 32@ 32 (for me @cn cn = 1@) 1)
and
@patch.y patch.y = (winSize.height + block.y - 1) / block.y@ block.y with @block.y block.y = 8@ 8 when @winSize.width winSize.width * cn > 32@ 32 (for me @cn cn = 1@) 1)
implying then that
@winSize.width winSize.width < 161@ 161
and
@winSize.height winSize.height < 41@ 41
I assume that this patch dimensions allow to divide the images in regions in order to run gpu routines and not to be limited by the gpu maximum operation number. But why are these dimensions so different ? In my case, the problem is the size height. Is there a reason it is limited to 41 ?

Here is my pseudo code :
<pre><code class="cpp">


Mat grayImgA = imread("imgA.png", CV_LOAD_IMAGE_GRAYSCALE);
Mat grayImgB = imread("imgB.png", CV_LOAD_IMAGE_GRAYSCALE);

gpu::GpuMat gpuGrayImgACopyROI(grayImgA);
gpu::GpuMat gpuGrayImgBCopyROI(grayImgB);

int maxPtNb = 5000;
float qualityLevel = 0.01f;
int minimumDistance = 4;

// extract features
gpu::GoodFeaturesToTrackDetector_GPU detector(maxPtNb, qualityLevel, minimumDistance);
gpu::GpuMat gpuCornersA;

detector(gpuGrayImgACopyROI, gpuCornersA);

// sparse lk optical flow
gpu::PyrLKOpticalFlow d_pyrLK;

d_pyrLK.winSize.width = 45;
d_pyrLK.winSize.height = 45;
d_pyrLK.maxLevel = maxLevel;
d_pyrLK.iters = 20;
d_pyrLK.derivLambda = 0.3;
d_pyrLK.useInitialFlow = false;

gpu::GpuMat d_nextPts;
gpu::GpuMat d_status;
gpu::GpuMat d_err;

d_pyrLK.sparse(gpuGrayImgA, gpuGrayImgB, gpuCornersA, d_nextPts, d_status, &d_err); // crash because of winSize.height >= 41
</code></pre>


Additionaly, I join to this report my two test images.

Thank you very much in advance for your answers and again, thank you for your great work.

Back