added optimization
This commit is contained in:
@@ -736,10 +736,39 @@ struct PrefilterInvoker : public ParallelLoopBody
|
||||
StereoBMParams* state;
|
||||
};
|
||||
|
||||
static bool ocl_stereo( InputArray _left, InputArray _right,
|
||||
static bool ocl_stereobm_opt( InputArray _left, InputArray _right,
|
||||
OutputArray _disp, StereoBMParams* state)
|
||||
{
|
||||
ocl::Kernel k("stereoBM", ocl::calib3d::stereobm_oclsrc, cv::format("-D SIZE=%d", state->numDisparities ) );
|
||||
int ndisp = state->numDisparities;
|
||||
ocl::Kernel k("stereoBM_opt", ocl::calib3d::stereobm_oclsrc, cv::format("-D csize=%d -D tsize=%d", ndisp*ndisp, ndisp) );
|
||||
if(k.empty())
|
||||
return false;
|
||||
|
||||
UMat left = _left.getUMat(), right = _right.getUMat();
|
||||
_disp.create(_left.size(), CV_16S);
|
||||
UMat disp = _disp.getUMat();
|
||||
|
||||
size_t globalThreads[3] = { left.cols, left.rows, 1 };
|
||||
size_t localThreads[3] = {ndisp, 1, 1};
|
||||
|
||||
int idx = 0;
|
||||
idx = k.set(idx, ocl::KernelArg::PtrReadOnly(left));
|
||||
idx = k.set(idx, ocl::KernelArg::PtrReadOnly(right));
|
||||
idx = k.set(idx, ocl::KernelArg::WriteOnly(disp));
|
||||
idx = k.set(idx, state->minDisparity);
|
||||
idx = k.set(idx, ndisp);
|
||||
idx = k.set(idx, state->preFilterCap);
|
||||
idx = k.set(idx, state->SADWindowSize);
|
||||
idx = k.set(idx, state->textureThreshold);
|
||||
idx = k.set(idx, state->uniquenessRatio);
|
||||
|
||||
return k.run(2, globalThreads, localThreads, false);
|
||||
}
|
||||
|
||||
static bool ocl_stereobm_bf(InputArray _left, InputArray _right,
|
||||
OutputArray _disp, StereoBMParams* state)
|
||||
{
|
||||
ocl::Kernel k("stereoBM_BF", ocl::calib3d::stereobm_oclsrc, cv::format("-D SIZE=%d", state->numDisparities ) );
|
||||
if(k.empty())
|
||||
return false;
|
||||
|
||||
@@ -763,6 +792,15 @@ static bool ocl_stereo( InputArray _left, InputArray _right,
|
||||
return k.run(2, globalThreads, NULL, false);
|
||||
}
|
||||
|
||||
static bool ocl_stereo(InputArray _left, InputArray _right,
|
||||
OutputArray _disp, StereoBMParams* state)
|
||||
{
|
||||
if(ocl::Device::getDefault().localMemSize() > state->numDisparities * state->numDisparities * sizeof(int) )
|
||||
return ocl_stereobm_opt(_left, _right, _disp, state);
|
||||
else
|
||||
return ocl_stereobm_bf(_left, _right, _disp, state);
|
||||
}
|
||||
|
||||
struct FindStereoCorrespInvoker : public ParallelLoopBody
|
||||
{
|
||||
FindStereoCorrespInvoker( const Mat& _left, const Mat& _right,
|
||||
|
||||
Reference in New Issue
Block a user