mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 14:13:15 +08:00
Bug #1823 : fixed patch size calculation in PyrLKOpticalFlow
This commit is contained in:
parent
092c1f98f6
commit
11eacb9d14
@ -124,6 +124,29 @@ void cv::gpu::PyrLKOpticalFlow::buildImagePyramid(const GpuMat& img0, vector<Gpu
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void calcPatchSize(cv::Size winSize, int cn, dim3& block, dim3& patch)
|
||||
{
|
||||
winSize.width *= cn;
|
||||
|
||||
if (winSize.width > 32 && winSize.width > 2 * winSize.height)
|
||||
{
|
||||
block.x = 32;
|
||||
block.y = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
block.x = block.y = 16;
|
||||
}
|
||||
|
||||
patch.x = (winSize.width + block.x - 1) / block.x;
|
||||
patch.y = (winSize.height + block.y - 1) / block.y;
|
||||
|
||||
block.z = patch.z = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void cv::gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, GpuMat& status, GpuMat* err)
|
||||
{
|
||||
using namespace cv::gpu::device::pyrlk;
|
||||
@ -142,19 +165,8 @@ void cv::gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& next
|
||||
|
||||
const int cn = prevImg.channels();
|
||||
|
||||
dim3 block;
|
||||
|
||||
if (winSize.width * cn > 32)
|
||||
{
|
||||
block.x = 32;
|
||||
block.y = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
block.x = block.y = 16;
|
||||
}
|
||||
|
||||
dim3 patch((winSize.width * cn + block.x - 1) / block.x, (winSize.height + block.y - 1) / block.y);
|
||||
dim3 block, patch;
|
||||
calcPatchSize(winSize, cn, block, patch);
|
||||
|
||||
CV_Assert(derivLambda >= 0);
|
||||
CV_Assert(maxLevel >= 0 && winSize.width > 2 && winSize.height > 2);
|
||||
|
@ -155,8 +155,13 @@ int main(int argc, const char* argv[])
|
||||
"{ h | help | false | print help message }"
|
||||
"{ l | left | | specify left image }"
|
||||
"{ r | right | | specify right image }"
|
||||
"{ g | gray | false | use grayscale sources [PyrLK Sparse] }"
|
||||
"{ p | points | 4000 | specify points count [GoodFeatureToTrack] }";
|
||||
"{ gray | gray | false | use grayscale sources [PyrLK Sparse] }"
|
||||
"{ win_size | win_size | 21 | specify windows size [PyrLK] }"
|
||||
"{ max_level | max_level | 3 | specify max level [PyrLK] }"
|
||||
"{ iters | iters | 30 | specify iterations count [PyrLK] }"
|
||||
"{ deriv_lambda | deriv_lambda | 0.5 | specify deriv lambda [PyrLK] }"
|
||||
"{ points | points | 4000 | specify points count [GoodFeatureToTrack] }"
|
||||
"{ min_dist | min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }";
|
||||
|
||||
CommandLineParser cmd(argc, argv, keys);
|
||||
|
||||
@ -178,7 +183,12 @@ int main(int argc, const char* argv[])
|
||||
}
|
||||
|
||||
bool useGray = cmd.get<bool>("gray");
|
||||
int winSize = cmd.get<int>("win_size");
|
||||
int maxLevel = cmd.get<int>("max_level");
|
||||
int iters = cmd.get<int>("iters");
|
||||
double derivLambda = cmd.get<double>("deriv_lambda");
|
||||
int points = cmd.get<int>("points");
|
||||
double minDist = cmd.get<double>("min_dist");
|
||||
|
||||
Mat frame0 = imread(fname0);
|
||||
Mat frame1 = imread(fname1);
|
||||
@ -210,7 +220,7 @@ int main(int argc, const char* argv[])
|
||||
|
||||
// goodFeaturesToTrack
|
||||
|
||||
GoodFeaturesToTrackDetector_GPU detector(points, 0.01, 0.0);
|
||||
GoodFeaturesToTrackDetector_GPU detector(points, 0.01, minDist);
|
||||
|
||||
GpuMat d_frame0Gray(frame0Gray);
|
||||
GpuMat d_prevPts;
|
||||
@ -221,6 +231,12 @@ int main(int argc, const char* argv[])
|
||||
|
||||
PyrLKOpticalFlow d_pyrLK;
|
||||
|
||||
d_pyrLK.winSize.width = winSize;
|
||||
d_pyrLK.winSize.height = winSize;
|
||||
d_pyrLK.maxLevel = maxLevel;
|
||||
d_pyrLK.iters = iters;
|
||||
d_pyrLK.derivLambda = derivLambda;
|
||||
|
||||
GpuMat d_frame0(frame0);
|
||||
GpuMat d_frame1(frame1);
|
||||
GpuMat d_frame1Gray(frame1Gray);
|
||||
|
Loading…
Reference in New Issue
Block a user