Commit 7c0e6efd authored by Alexander Alekhin's avatar Alexander Alekhin

stereo: fix massive invalid range access and uninitialized values

parent 9c0e1525
...@@ -64,7 +64,9 @@ PERF_TEST_P( s_bm, sgm_perf, ...@@ -64,7 +64,9 @@ PERF_TEST_P( s_bm, sgm_perf,
Mat out1(sz, sdepth); Mat out1(sz, sdepth);
Ptr<StereoBinarySGBM> sgbm = StereoBinarySGBM::create(0, 16, 5); Ptr<StereoBinarySGBM> sgbm = StereoBinarySGBM::create(0, 16, 5);
sgbm->setBinaryKernelType(CV_DENSE_CENSUS); sgbm->setBinaryKernelType(CV_DENSE_CENSUS);
declare.in(left, WARMUP_RNG) declare
.in(left, WARMUP_RNG)
.in(right, WARMUP_RNG)
.out(out1) .out(out1)
.time(0.1) .time(0.1)
.iterations(20); .iterations(20);
...@@ -103,7 +105,9 @@ PERF_TEST_P( s_bm, bm_perf, ...@@ -103,7 +105,9 @@ PERF_TEST_P( s_bm, bm_perf,
sbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM); sbm->setSpekleRemovalTechnique(CV_SPECKLE_REMOVAL_AVG_ALGORITHM);
sbm->setUsePrefilter(false); sbm->setUsePrefilter(false);
declare.in(left, WARMUP_RNG) declare
.in(left, WARMUP_RNG)
.in(right, WARMUP_RNG)
.out(out1) .out(out1)
.time(0.1) .time(0.1)
.iterations(20); .iterations(20);
......
...@@ -64,12 +64,12 @@ namespace cv ...@@ -64,12 +64,12 @@ namespace cv
int stride = (int)image1.step; int stride = (int)image1.step;
if(type == CV_DENSE_CENSUS) if(type == CV_DENSE_CENSUS)
{ {
parallel_for_( Range(n2, image1.rows - n2), parallel_for_(Range(0, image1.rows),
CombinedDescriptor<1,1,1,2,CensusKernel<2> >(image1.cols, image1.rows,stride,n2,costs,CensusKernel<2>(images),n2)); CombinedDescriptor<1,1,1,2,CensusKernel<2> >(image1.cols, image1.rows,stride,n2,costs,CensusKernel<2>(images),n2));
} }
else if(type == CV_SPARSE_CENSUS) else if(type == CV_SPARSE_CENSUS)
{ {
parallel_for_( Range(n2, image1.rows - n2), parallel_for_(Range(0, image1.rows),
CombinedDescriptor<2,2,1,2,CensusKernel<2> >(image1.cols, image1.rows, stride,n2,costs,CensusKernel<2>(images),n2)); CombinedDescriptor<2,2,1,2,CensusKernel<2> >(image1.cols, image1.rows, stride,n2,costs,CensusKernel<2>(images),n2));
} }
} }
...@@ -87,12 +87,12 @@ namespace cv ...@@ -87,12 +87,12 @@ namespace cv
int stride = (int)image1.step; int stride = (int)image1.step;
if(type == CV_DENSE_CENSUS) if(type == CV_DENSE_CENSUS)
{ {
parallel_for_( Range(n2, image1.rows - n2), parallel_for_(Range(0, image1.rows),
CombinedDescriptor<1,1,1,1,CensusKernel<1> >(image1.cols, image1.rows,stride,n2,costs,CensusKernel<1>(images),n2)); CombinedDescriptor<1,1,1,1,CensusKernel<1> >(image1.cols, image1.rows,stride,n2,costs,CensusKernel<1>(images),n2));
} }
else if(type == CV_SPARSE_CENSUS) else if(type == CV_SPARSE_CENSUS)
{ {
parallel_for_( Range(n2, image1.rows - n2), parallel_for_(Range(0, image1.rows),
CombinedDescriptor<2,2,1,1,CensusKernel<1> >(image1.cols, image1.rows,stride,n2,costs,CensusKernel<1>(images),n2)); CombinedDescriptor<2,2,1,1,CensusKernel<1> >(image1.cols, image1.rows,stride,n2,costs,CensusKernel<1>(images),n2));
} }
} }
...@@ -106,7 +106,7 @@ namespace cv ...@@ -106,7 +106,7 @@ namespace cv
int n2 = (kernelSize) >> 1; int n2 = (kernelSize) >> 1;
Mat images[] = {img1, img2}; Mat images[] = {img1, img2};
int *date[] = { (int *)dist1.data, (int *)dist2.data}; int *date[] = { (int *)dist1.data, (int *)dist2.data};
parallel_for_(Range(n2, img1.rows - n2), StarKernelCensus<2>(images, n2,date)); parallel_for_(Range(0, img1.rows), StarKernelCensus<2>(images, n2,date));
} }
//single version of star census //single version of star census
CV_EXPORTS void starCensusTransform(const Mat &img1, int kernelSize, Mat &dist) CV_EXPORTS void starCensusTransform(const Mat &img1, int kernelSize, Mat &dist)
...@@ -118,7 +118,7 @@ namespace cv ...@@ -118,7 +118,7 @@ namespace cv
int n2 = (kernelSize) >> 1; int n2 = (kernelSize) >> 1;
Mat images[] = {img1}; Mat images[] = {img1};
int *date[] = { (int *)dist.data}; int *date[] = { (int *)dist.data};
parallel_for_(Range(n2, img1.rows - n2), StarKernelCensus<1>(images, n2,date)); parallel_for_(Range(0, img1.rows), StarKernelCensus<1>(images, n2,date));
} }
//Modified census transforms //Modified census transforms
//the first one deals with small illumination changes //the first one deals with small illumination changes
...@@ -139,7 +139,7 @@ namespace cv ...@@ -139,7 +139,7 @@ namespace cv
if(type == CV_MODIFIED_CENSUS_TRANSFORM) if(type == CV_MODIFIED_CENSUS_TRANSFORM)
{ {
//MCT //MCT
parallel_for_( Range(n2, img1.rows - n2), parallel_for_(Range(0, img1.rows),
CombinedDescriptor<2,4,2, 2,MCTKernel<2> >(img1.cols, img1.rows,stride,n2,date,MCTKernel<2>(images,t),n2)); CombinedDescriptor<2,4,2, 2,MCTKernel<2> >(img1.cols, img1.rows,stride,n2,date,MCTKernel<2>(images,t),n2));
} }
else if(type == CV_MEAN_VARIATION) else if(type == CV_MEAN_VARIATION)
...@@ -159,7 +159,7 @@ namespace cv ...@@ -159,7 +159,7 @@ namespace cv
(int *)integralImage1.data, (int *)integralImage1.data,
(int *)integralImage2.data (int *)integralImage2.data
}; };
parallel_for_( Range(n2, img1.rows - n2), parallel_for_(Range(0, img1.rows),
CombinedDescriptor<2,3,2,2, MVKernel<2> >(img1.cols, img1.rows,stride,n2,date,MVKernel<2>(images,integral),n2)); CombinedDescriptor<2,3,2,2, MVKernel<2> >(img1.cols, img1.rows,stride,n2,date,MVKernel<2>(images,integral),n2));
} }
} }
...@@ -177,7 +177,7 @@ namespace cv ...@@ -177,7 +177,7 @@ namespace cv
if(type == CV_MODIFIED_CENSUS_TRANSFORM) if(type == CV_MODIFIED_CENSUS_TRANSFORM)
{ {
//MCT //MCT
parallel_for_(Range(n2, img1.rows - n2), parallel_for_(Range(0, img1.rows),
CombinedDescriptor<2,4,2, 1,MCTKernel<1> >(img1.cols, img1.rows,stride,n2,date,MCTKernel<1>(images,t),n2)); CombinedDescriptor<2,4,2, 1,MCTKernel<1> >(img1.cols, img1.rows,stride,n2,date,MCTKernel<1>(images,t),n2));
} }
else if(type == CV_MEAN_VARIATION) else if(type == CV_MEAN_VARIATION)
...@@ -189,7 +189,7 @@ namespace cv ...@@ -189,7 +189,7 @@ namespace cv
CV_CheckGE(integralImage.cols, img1.cols, ""); CV_CheckGE(integralImage.cols, img1.cols, "");
CV_CheckGE(integralImage.rows, img1.rows, ""); CV_CheckGE(integralImage.rows, img1.rows, "");
int *integral[] = { (int *)integralImage.data}; int *integral[] = { (int *)integralImage.data};
parallel_for_(Range(n2, img1.rows - n2), parallel_for_(Range(0, img1.rows),
CombinedDescriptor<2,3,2,1, MVKernel<1> >(img1.cols, img1.rows,stride,n2,date,MVKernel<1>(images,integral),n2)); CombinedDescriptor<2,3,2,1, MVKernel<1> >(img1.cols, img1.rows,stride,n2,date,MVKernel<1>(images,integral),n2));
} }
} }
...@@ -209,11 +209,11 @@ namespace cv ...@@ -209,11 +209,11 @@ namespace cv
int stride = (int)img1.step; int stride = (int)img1.step;
if(type == CV_CS_CENSUS) if(type == CV_CS_CENSUS)
{ {
parallel_for_(Range(n2, img1.rows - n2), SymetricCensus<2>(imag, n2,date)); parallel_for_(Range(0, img1.rows), SymetricCensus<2>(imag, n2,date));
} }
else if(type == CV_MODIFIED_CS_CENSUS) else if(type == CV_MODIFIED_CS_CENSUS)
{ {
parallel_for_(Range(n2, img1.rows - n2), parallel_for_(Range(0, img1.rows),
CombinedDescriptor<1,1,1,2,ModifiedCsCensus<2> >(img1.cols, img1.rows,stride,n2,date,ModifiedCsCensus<2>(images,n2),1)); CombinedDescriptor<1,1,1,2,ModifiedCsCensus<2> >(img1.cols, img1.rows,stride,n2,date,ModifiedCsCensus<2>(images,n2),1));
} }
} }
...@@ -231,11 +231,11 @@ namespace cv ...@@ -231,11 +231,11 @@ namespace cv
int stride = (int)img1.step; int stride = (int)img1.step;
if(type == CV_CS_CENSUS) if(type == CV_CS_CENSUS)
{ {
parallel_for_( Range(n2, img1.rows - n2), SymetricCensus<1>(imag, n2,date)); parallel_for_(Range(0, img1.rows), SymetricCensus<1>(imag, n2,date));
} }
else if(type == CV_MODIFIED_CS_CENSUS) else if(type == CV_MODIFIED_CS_CENSUS)
{ {
parallel_for_( Range(n2, img1.rows - n2), parallel_for_( Range(0, img1.rows),
CombinedDescriptor<1,1,1,1,ModifiedCsCensus<1> >(img1.cols, img1.rows,stride,n2,date,ModifiedCsCensus<1>(images,n2),1)); CombinedDescriptor<1,1,1,1,ModifiedCsCensus<1> >(img1.cols, img1.rows,stride,n2,date,ModifiedCsCensus<1>(images,n2),1));
} }
} }
...@@ -250,7 +250,7 @@ namespace cv ...@@ -250,7 +250,7 @@ namespace cv
int height = image.rows; int height = image.rows;
cost.setTo(0); cost.setTo(0);
int *c = (int *)cost.data; int *c = (int *)cost.data;
parallel_for_(Range(win + 1, height - win - 1),MeanKernelIntegralImage(image,win,scalling,c)); parallel_for_(Range(0, height), MeanKernelIntegralImage(image, win, scalling, c));
} }
} }
} }
...@@ -210,11 +210,18 @@ namespace cv ...@@ -210,11 +210,18 @@ namespace cv
n2_stop = k2Stop; n2_stop = k2Stop;
} }
void operator()(const cv::Range &r) const CV_OVERRIDE { void operator()(const cv::Range &r) const CV_OVERRIDE {
for (int i = r.start; i <= r.end ; i++) for (int i = r.start; i < r.end ; i++)
{ {
int rWidth = i * stride_; int rWidth = i * stride_;
for (int j = n2 + 2; j <= width - n2 - 2; j++) for (int j = 0; j < width; j++)
{ {
if (i < n2 || i >= height - n2 || j < n2 + 2 || j >= width - n2 - 2)
{
for(int l = 0; l < nr_img; l++)
dst[l][rWidth + j] = 0; // TODO out of range value?
continue;
}
int c[nr_img]; int c[nr_img];
memset(c, 0, sizeof(c[0]) * nr_img); memset(c, 0, sizeof(c[0]) * nr_img);
for(int step = step_start; step <= step_end; step += step_inc) for(int step = step_start; step <= step_end; step += step_inc)
...@@ -243,21 +250,33 @@ namespace cv ...@@ -243,21 +250,33 @@ namespace cv
class MeanKernelIntegralImage : public ParallelLoopBody class MeanKernelIntegralImage : public ParallelLoopBody
{ {
private: private:
int *img; const Mat& img;
int windowSize,width; int windowSize;
float scalling; float scalling;
int *c; int *c;
public: public:
MeanKernelIntegralImage(const cv::Mat &image, int window,float scale, int *cost): MeanKernelIntegralImage(const cv::Mat &image, int window,float scale, int *cost):
img((int *)image.data),windowSize(window) ,width(image.cols) ,scalling(scale) , c(cost){}; img(image),windowSize(window), scalling(scale), c(cost)
void operator()(const cv::Range &r) const CV_OVERRIDE { {}
for (int i = r.start; i <= r.end; i++) void operator()(const cv::Range &r) const CV_OVERRIDE
{
const int width = img.cols;
const int height = img.rows;
for (int i = r.start; i < r.end; i++)
{ {
int y0 = std::max(0, i - windowSize + 1);
int y1 = std::min(height - 1, i + windowSize);
int iw = i * width; int iw = i * width;
for (int j = windowSize + 1; j <= width - windowSize - 1; j++) for (int j = 0; j < width; j++)
{ {
c[iw + j] = (int)((img[(i + windowSize - 1) * width + j + windowSize - 1] + img[(i - windowSize - 1) * width + j - windowSize - 1] int x0 = std::max(0, j - windowSize + 1);
- img[(i + windowSize) * width + j - windowSize] - img[(i - windowSize) * width + j + windowSize]) * scalling); int x1 = std::min(height - 1, j + windowSize);
c[iw + j] = (int)(
(
img.at<int>(y0, x0) + img.at<int>(y0, x0) -
img.at<int>(y1, x0) - img.at<int>(y0, x1)
) * scalling);
} }
} }
} }
...@@ -285,13 +304,18 @@ namespace cv ...@@ -285,13 +304,18 @@ namespace cv
stride_ = (int)img[0].step; stride_ = (int)img[0].step;
} }
void operator()(const cv::Range &r) const CV_OVERRIDE { void operator()(const cv::Range &r) const CV_OVERRIDE {
for (int i = r.start; i <= r.end ; i++) for (int i = r.start; i < r.end; i++)
{ {
int rWidth = i * stride_; int rWidth = i * stride_;
for (int j = n2; j <= width - n2; j++) for (int j = 0; j < width; j++)
{ {
for(int d = 0 ; d < im_num; d++) for(int d = 0 ; d < im_num; d++)
{ {
if (i < n2 || i >= height - n2 || j < n2 || j >= width - n2)
{
dst[d][rWidth + j] = 0; // TODO out of range value?
continue;
}
int c = 0; int c = 0;
for(int step = 4; step > 0; step--) for(int step = 4; step > 0; step--)
{ {
...@@ -377,13 +401,18 @@ namespace cv ...@@ -377,13 +401,18 @@ namespace cv
stride_ = (int)img[0].step; stride_ = (int)img[0].step;
} }
void operator()(const cv::Range &r) const CV_OVERRIDE { void operator()(const cv::Range &r) const CV_OVERRIDE {
for (int i = r.start; i <= r.end ; i++) for (int i = r.start; i < r.end ; i++)
{ {
int distV = i*stride_; int distV = i*stride_;
for (int j = n2; j <= width - n2; j++) for (int j = 0; j < width; j++)
{ {
for(int d = 0; d < im_num; d++) for(int d = 0; d < im_num; d++)
{ {
if (i < n2 || i >= height - n2 || j < n2 || j >= width - n2)
{
dst[d][distV + j] = 0; // TODO out of range value?
continue;
}
int c = 0; int c = 0;
//the classic center symetric census which compares the curent pixel with its symetric not its center. //the classic center symetric census which compares the curent pixel with its symetric not its center.
for (int ii = -n2; ii <= 0; ii++) for (int ii = -n2; ii <= 0; ii++)
......
...@@ -64,7 +64,7 @@ namespace cv ...@@ -64,7 +64,7 @@ namespace cv
//!the confidence to which a min disparity found is good or not //!the confidence to which a min disparity found is good or not
double confidenceCheck; double confidenceCheck;
//!the LUT used in case SSE is not available //!the LUT used in case SSE is not available
int hamLut[65537]; int hamLut[65536]; // FIXIT use preferined 8-bit lookup table for hamming
//!function used for getting the minimum disparity from the cost volume" //!function used for getting the minimum disparity from the cost volume"
static int minim(short *c, int iwpj, int widthDisp,const double confidence, const int search_region) static int minim(short *c, int iwpj, int widthDisp,const double confidence, const int search_region)
{ {
...@@ -131,7 +131,7 @@ namespace cv ...@@ -131,7 +131,7 @@ namespace cv
//!a pre processing function that generates the Hamming LUT in case the algorithm will ever be used on platform where SSE is not available //!a pre processing function that generates the Hamming LUT in case the algorithm will ever be used on platform where SSE is not available
void hammingLut() void hammingLut()
{ {
for (int i = 0; i <= 65536; i++) for (int i = 0; i < 65536; i++)
{ {
int dist = 0; int dist = 0;
int j = i; int j = i;
...@@ -157,19 +157,16 @@ namespace cv ...@@ -157,19 +157,16 @@ namespace cv
hammingDistance(const Mat &leftImage, const Mat &rightImage, short *cost, int maxDisp, int kerSize, int *hammingLUT): hammingDistance(const Mat &leftImage, const Mat &rightImage, short *cost, int maxDisp, int kerSize, int *hammingLUT):
left((int *)leftImage.data), right((int *)rightImage.data), c(cost), v(maxDisp),kernelSize(kerSize),width(leftImage.cols), MASK(65535), hammLut(hammingLUT){} left((int *)leftImage.data), right((int *)rightImage.data), c(cost), v(maxDisp),kernelSize(kerSize),width(leftImage.cols), MASK(65535), hammLut(hammingLUT){}
void operator()(const cv::Range &r) const CV_OVERRIDE { void operator()(const cv::Range &r) const CV_OVERRIDE {
for (int i = r.start; i <= r.end ; i++) for (int i = r.start; i < r.end ; i++)
{ {
int iw = i * width; int iw = i * width;
for (int j = kernelSize; j < width - kernelSize; j++) for (int j = kernelSize; j < width - kernelSize; j++)
{ {
int j2; int iwj = iw + j;
int xorul;
int iwj;
iwj = iw + j;
for (int d = 0; d <= v; d++) for (int d = 0; d <= v; d++)
{ {
j2 = (0 > j - d) ? (0) : (j - d); int j2 = std::max(0, j - d);
xorul = left[(iwj)] ^ right[(iw + j2)]; int xorul = left[(iwj)] ^ right[(iw + j2)];
#if CV_POPCNT #if CV_POPCNT
if (checkHardwareSupport(CV_CPU_POPCNT)) if (checkHardwareSupport(CV_CPU_POPCNT))
{ {
...@@ -203,16 +200,25 @@ namespace cv ...@@ -203,16 +200,25 @@ namespace cv
parSum = (short *)partialSums.data; parSum = (short *)partialSums.data;
} }
void operator()(const cv::Range &r) const CV_OVERRIDE { void operator()(const cv::Range &r) const CV_OVERRIDE {
for (int i = r.start; i <= r.end; i++) for (int i = r.start; i < r.end; i++)
{ {
int iwi = (i - 1) * width; int iwi = i * width;
for (int j = win + 1; j <= width - win - 1; j++) for (int j = 0; j <= width; j++)
{ {
int w = (iwi + j) * (maxDisp + 1);
if (i < win + 1 || i >= height - win - 1 || j < win + 1 || j >= width - win - 1)
{
for (int d = 0; d <= maxDisp; d++)
{
c[w + d] = 0;
}
continue;
}
int w1 = ((i + win + 1) * width + j + win) * (maxDisp + 1); int w1 = ((i + win + 1) * width + j + win) * (maxDisp + 1);
int w2 = ((i - win) * width + j - win - 1) * (maxDisp + 1); int w2 = ((i - win) * width + j - win - 1) * (maxDisp + 1);
int w3 = ((i + win + 1) * width + j - win - 1) * (maxDisp + 1); int w3 = ((i + win + 1) * width + j - win - 1) * (maxDisp + 1);
int w4 = ((i - win) * width + j + win) * (maxDisp + 1); int w4 = ((i - win) * width + j + win) * (maxDisp + 1);
int w = (iwi + j - 1) * (maxDisp + 1);
for (int d = 0; d <= maxDisp; d++) for (int d = 0; d <= maxDisp; d++)
{ {
c[w + d] = parSum[w1 + d] + parSum[w2 + d] c[w + d] = parSum[w1 + d] + parSum[w2 + d]
...@@ -244,7 +250,7 @@ namespace cv ...@@ -244,7 +250,7 @@ namespace cv
confCheck = confidence; confCheck = confidence;
} }
void operator()(const cv::Range &r) const CV_OVERRIDE { void operator()(const cv::Range &r) const CV_OVERRIDE {
for (int i = r.start; i <= r.end ; i++) for (int i = r.start; i < r.end ; i++)
{ {
int lr; int lr;
int v = -1; int v = -1;
...@@ -301,10 +307,16 @@ namespace cv ...@@ -301,10 +307,16 @@ namespace cv
width = originalImage.cols; width = originalImage.cols;
} }
void operator()(const cv::Range &r) const CV_OVERRIDE { void operator()(const cv::Range &r) const CV_OVERRIDE {
for (int m = r.start; m <= r.end; m++) for (int m = r.start; m < r.end; m++)
{ {
for (int n = 4; n < width - 4; ++n) for (int n = 0; n < width; ++n)
{ {
if (m < 1 || m >= height - 1 || n < 4 || n >= width - 4)
{
filtered[m * width + n] = original[m * width + n]; // FIXIT replace with OpenCV function
continue;
}
int k = 0; int k = 0;
T window[9]; T window[9];
for (int i = n - 4; i <= n + 4; ++i) for (int i = n - 4; i <= n + 4; ++i)
...@@ -341,10 +353,16 @@ namespace cv ...@@ -341,10 +353,16 @@ namespace cv
width = originalImage.cols; width = originalImage.cols;
} }
void operator()(const Range &r) const CV_OVERRIDE { void operator()(const Range &r) const CV_OVERRIDE {
for (int n = r.start; n <= r.end; ++n) for (int n = r.start; n < r.end; ++n)
{ {
for (int m = 4; m < height - 4; ++m) for (int m = 4; m < height - 4; ++m)
{ {
if (m < 4 || m >= height - 4 || n < 1 || n >= width - 1)
{
filtered[m * width + n] = original[m * width + n]; // FIXIT replace with OpenCV function
continue;
}
int k = 0; int k = 0;
T window[9]; T window[9];
for (int i = m - 4; i <= m + 4; ++i) for (int i = m - 4; i <= m + 4; ++i)
...@@ -430,11 +448,11 @@ namespace cv ...@@ -430,11 +448,11 @@ namespace cv
short *c = (short *)cost.data; short *c = (short *)cost.data;
short *ham = (short *)hammingDistanceCost.data; short *ham = (short *)hammingDistanceCost.data;
memset(c, 0, sizeof(c[0]) * (width + 1) * (height + 1) * (maxDisp + 1)); memset(c, 0, sizeof(c[0]) * (width + 1) * (height + 1) * (maxDisp + 1));
for (int i = 1; i <= height; i++) for (int i = 1; i < height; i++)
{ {
int iw = i * width; int iw = i * width;
int iwi = (i - 1) * width; int iwi = (i - 1) * width;
for (int j = 1; j <= width; j++) for (int j = 1; j < width; j++)
{ {
int iwj = (iw + j) * (maxDisp + 1); int iwj = (iw + j) * (maxDisp + 1);
int iwjmu = (iw + j - 1) * (maxDisp + 1); int iwjmu = (iw + j - 1) * (maxDisp + 1);
...@@ -445,9 +463,9 @@ namespace cv ...@@ -445,9 +463,9 @@ namespace cv
} }
} }
} }
for (int i = 1; i <= height; i++) for (int i = 1; i < height; i++)
{ {
for (int j = 1; j <= width; j++) for (int j = 1; j < width; j++)
{ {
int iwj = (i * width + j) * (maxDisp + 1); int iwj = (i * width + j) * (maxDisp + 1);
int iwjmu = ((i - 1) * width + j) * (maxDisp + 1); int iwjmu = ((i - 1) * width + j) * (maxDisp + 1);
...@@ -464,13 +482,12 @@ namespace cv ...@@ -464,13 +482,12 @@ namespace cv
CV_Assert(windowSize % 2 != 0); CV_Assert(windowSize % 2 != 0);
CV_Assert(partialSums.rows == cost.rows); CV_Assert(partialSums.rows == cost.rows);
CV_Assert(partialSums.cols == cost.cols); CV_Assert(partialSums.cols == cost.cols);
int win = windowSize / 2;
short *c = (short *)cost.data; short *c = (short *)cost.data;
int maxDisp = maxDisparity; int maxDisp = maxDisparity;
int width = cost.cols / ( maxDisp + 1) - 1; int width = cost.cols / ( maxDisp + 1) - 1;
int height = cost.rows - 1; int height = cost.rows - 1;
memset(c, 0, sizeof(c[0]) * width * height * (maxDisp + 1)); memset(c, 0, sizeof(c[0]) * width * height * (maxDisp + 1));
parallel_for_(cv::Range(win + 1,height - win - 1), agregateCost(partialSums,windowSize,maxDisp,cost)); parallel_for_(cv::Range(0, height), agregateCost(partialSums,windowSize, maxDisp, cost));
} }
//!remove small regions that have an area smaller than t, we fill the region with the average of the good pixels around it //!remove small regions that have an area smaller than t, we fill the region with the average of the good pixels around it
template <typename T> template <typename T>
...@@ -571,7 +588,7 @@ namespace cv ...@@ -571,7 +588,7 @@ namespace cv
int width = costVolume.cols / ( disparity + 1) - 1; int width = costVolume.cols / ( disparity + 1) - 1;
int height = costVolume.rows - 1; int height = costVolume.rows - 1;
memset(map, 0, sizeof(map[0]) * width * height); memset(map, 0, sizeof(map[0]) * width * height);
parallel_for_(Range(0,height - 1), makeMap(costVolume,th,disparity,confidenceCheck,scallingFactor,mapFinal)); parallel_for_(Range(0, height), makeMap(costVolume,th,disparity,confidenceCheck,scallingFactor,mapFinal));
} }
public: public:
//!a median filter of 1x9 and 9x1 //!a median filter of 1x9 and 9x1
...@@ -581,7 +598,7 @@ namespace cv ...@@ -581,7 +598,7 @@ namespace cv
{ {
CV_Assert(originalImage.rows == filteredImage.rows); CV_Assert(originalImage.rows == filteredImage.rows);
CV_Assert(originalImage.cols == filteredImage.cols); CV_Assert(originalImage.cols == filteredImage.cols);
parallel_for_(Range(1,originalImage.rows - 2), Median1x9<T>(originalImage,filteredImage)); parallel_for_(Range(0, originalImage.rows), Median1x9<T>(originalImage,filteredImage));
} }
//!9x1 median filter //!9x1 median filter
template<typename T> template<typename T>
...@@ -589,7 +606,7 @@ namespace cv ...@@ -589,7 +606,7 @@ namespace cv
{ {
CV_Assert(originalImage.cols == filteredImage.cols); CV_Assert(originalImage.cols == filteredImage.cols);
CV_Assert(originalImage.cols == filteredImage.cols); CV_Assert(originalImage.cols == filteredImage.cols);
parallel_for_(Range(1,originalImage.cols - 2), Median9x1<T>(originalImage,filteredImage)); parallel_for_(Range(0, originalImage.cols), Median9x1<T>(originalImage,filteredImage));
} }
//!constructor for the matching class //!constructor for the matching class
//!maxDisp - represents the maximum disparity //!maxDisp - represents the maximum disparity
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment