OpenCV 2.4.0, cv::gpu::PyrLKOpticalFlow::sparse - make program crash when modifying the search window size (Bug #1823)
Description
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
.
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
, ln 162) there is the following assertion :CV_Assert(patch.x > 0 && patch.x < 6 && patch.y > 0 && patch.y < 6);
withpatch.x = (winSize.width * cn + block.x - 1) / block.x
with block.x = 32
when winSize.width * cn > 32
(for me cn = 1
)
andpatch.y = (winSize.height + block.y - 1) / block.y
with block.y = 8
when winSize.width * cn > 32
(for me cn = 1
)
implying then thatwinSize.width < 161
andwinSize.height < 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 :
1Mat grayImgA = imread("imgA.png", CV_LOAD_IMAGE_GRAYSCALE);
2Mat grayImgB = imread("imgB.png", CV_LOAD_IMAGE_GRAYSCALE);
3
4gpu::GpuMat gpuGrayImgACopyROI(grayImgA);
5gpu::GpuMat gpuGrayImgBCopyROI(grayImgB);
6
7int maxPtNb = 5000;
8float qualityLevel = 0.01f;
9int minimumDistance = 4;
10
11// extract features
12gpu::GoodFeaturesToTrackDetector_GPU detector(maxPtNb, qualityLevel, minimumDistance);
13gpu::GpuMat gpuCornersA;
14
15detector(gpuGrayImgACopyROI, gpuCornersA);
16
17// sparse lk optical flow
18gpu::PyrLKOpticalFlow d_pyrLK;
19
20d_pyrLK.winSize.width = 45;
21d_pyrLK.winSize.height = 45;
22d_pyrLK.maxLevel = maxLevel;
23d_pyrLK.iters = 20;
24d_pyrLK.derivLambda = 0.3;
25d_pyrLK.useInitialFlow = false;
26
27gpu::GpuMat d_nextPts;
28gpu::GpuMat d_status;
29gpu::GpuMat d_err;
30
31d_pyrLK.sparse(gpuGrayImgA, gpuGrayImgB, gpuCornersA, d_nextPts, d_status, &d_err); // crash because of winSize.height >= 41
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.
Associated revisions
Bug #1823 : fixed patch size calculation in PyrLKOpticalFlow
Merge pull request #1823 from ilya-lavrenov:ocl_abs_sum
History
Updated by Anatoly Baksheev almost 13 years ago
- Assignee changed from Anatoly Baksheev to Vladislav Vinogradov
Updated by Andrey Kamaev almost 13 years ago
- Description changed from Hello all, First of all, thanks a lot for your great job. I am using OpenCV ... to Hello all, First of all, thanks a lot for your great job. I am using OpenCV ... More
Updated by Vladislav Vinogradov almost 13 years ago
Window size is limited due memory resource limitation. I fixed patch size calculation for case cn = 1. Now both width and height are limited to 95.
- Status changed from Open to Done
Updated by Francois Picard almost 13 years ago
Thanks ! I'll give it a try !