jeremy
March 2, 2022, 6:15am
1
CV_Assert(prevPyr.size() && nextPyr.size() && "Pyramid needs to at least contain the original matrix as the first element");
CV_Assert(prevPyr[0].size() == nextPyr[0].size());
CV_Assert(prevPts.rows == 1 && prevPts.type() == CV_32FC2);
CV_Assert(maxLevel_ >= 0);
CV_Assert(winSize_[0] > 2 && winSize_[1] > 2);
if (useInitialFlow_)
CV_Assert(nextPts.size() == prevPts.size() && nextPts.type() == prevPts.type());
else
ensureSizeIsEnough(1, prevPts.cols, prevPts.type(), nextPts);
GpuMat temp1 = (useInitialFlow_ ? nextPts : prevPts).reshape(1);
GpuMat temp2 = nextPts.reshape(1);
cuda::multiply(temp1, Scalar::all(1.0 / (1 << maxLevel_) / 2.0), temp2, 1, -1, stream);
ensureSizeIsEnough(1, prevPts.cols, CV_8UC1, status);
status.setTo(Scalar::all(1), stream);
if (err)
ensureSizeIsEnough(1, prevPts.cols, CV_32FC1, *err);
Hi,I am try to understand source code of sparsePyrLKOptical algorithm, i see code in page above, it seems temp1, temp2 is used for nothing, just a multiply operation, so I wonder what are they used for? or just debug code ,forgetting deleted.
by the way, Is there any material helping me to get this algorithm more clearly?, thank you.
looks like it to me as well.
The algorithm and its original paper:
In computer vision, the Lucas–Kanade method is a widely used differential method for optical flow estimation developed by Bruce D. Lucas and Takeo Kanade. It assumes that the flow is essentially constant in a local neighbourhood of the pixel under consideration, and solves the basic optical flow equations for all the pixels in that neighbourhood, by the least squares criterion.
By combining information from several nearby pixels, the Lucas–Kanade method can often resolve the inherent ambiguity o...
jeremy
March 3, 2022, 6:02am
3
but, when i comment the 3 lines(line 166, 167,168) out, the output result seems to be wrong…
ah okay, then
GpuMat temp2 = nextPts.reshape(1);
must cause the result to go into nextPts
. the reshape is probably a view, not a copy.
jeremy
March 4, 2022, 2:24am
5
yes, reshape returns another header for same data I’ll check it.