}
-static const int DISPARITY_SHIFT = 4;
+static int DISPARITY_SHIFT;
+static const int DISPARITY_SHIFT_16S = 4;
+static const int DISPARITY_SHIFT_32S = 8;
#if CV_SSE2
static void findStereoCorrespondenceBM_SSE2( const Mat& left, const Mat& right,
}
#endif
+template <typename mType>
static void
-findStereoCorrespondenceBM( const Mat& left, const Mat& right,
+findStereoCorrespondenceBM_( const Mat& left, const Mat& right,
Mat& disp, Mat& cost, const StereoBMParams& state,
uchar* buf, int _dy0, int _dy1 )
{
int ftzero = state.preFilterCap;
int textureThreshold = state.textureThreshold;
int uniquenessRatio = state.uniquenessRatio;
- short FILTERED = (short)((mindisp - 1) << DISPARITY_SHIFT);
+ mType FILTERED = (mType)((mindisp - 1) << DISPARITY_SHIFT);
#if CV_NEON
CV_Assert (ndisp % 8 == 0);
const uchar* lptr0 = left.ptr() + lofs;
const uchar* rptr0 = right.ptr() + rofs;
const uchar *lptr, *lptr_sub, *rptr;
- short* dptr = disp.ptr<short>();
+ mType* dptr = disp.ptr<mType>();
int sstep = (int)left.step;
int dstep = (int)(disp.step/sizeof(dptr[0]));
int cstep = (height+dy0+dy1)*ndisp;
sad[ndisp] = sad[ndisp-2];
int p = sad[mind+1], n = sad[mind-1];
d = p + n - 2*sad[mind] + std::abs(p - n);
- dptr[y*dstep] = (short)(((ndisp - mind - 1 + mindisp)*256 + (d != 0 ? (p-n)*256/d : 0) + 15) >> 4);
+ dptr[y*dstep] = (mType)(((ndisp - mind - 1 + mindisp)*256 + (d != 0 ? (p-n)*256/d : 0) + 15)
+ >> (DISPARITY_SHIFT_32S - DISPARITY_SHIFT));
costptr[y*coststep] = sad[mind];
}
}
}
}
+static void
+findStereoCorrespondenceBM( const Mat& left, const Mat& right,
+ Mat& disp, Mat& cost, const StereoBMParams& state,
+ uchar* buf, int _dy0, int _dy1 )
+{
+ if(disp.type() == CV_16S){
+ DISPARITY_SHIFT = DISPARITY_SHIFT_16S;
+ findStereoCorrespondenceBM_<short>(left, right, disp, cost, state,
+ buf, _dy0, _dy1 );
+ } else {
+ DISPARITY_SHIFT = DISPARITY_SHIFT_32S;
+ findStereoCorrespondenceBM_<int>(left, right, disp, cost, state,
+ buf, _dy0, _dy1 );
+ }
+}
+
#ifdef HAVE_OPENCL
static bool ocl_prefiltering(InputArray left0, InputArray right0, OutputArray left, OutputArray right, StereoBMParams* state)
{
Mat disp = disp0;
if( dtype == CV_32F )
{
- dispbuf.create(disp0.size(), CV_16S);
+ dispbuf.create(disp0.size(), CV_32S);
disp = dispbuf;
}