|
|
|
@ -857,22 +857,20 @@ Rect getValidDisparityROI( Rect roi1, Rect roi2, |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSize, |
|
|
|
|
double _maxDiff, InputOutputArray __buf ) |
|
|
|
|
namespace |
|
|
|
|
{ |
|
|
|
|
Mat img = _img.getMat(); |
|
|
|
|
Mat temp, &_buf = __buf.needed() ? __buf.getMatRef() : temp; |
|
|
|
|
CV_Assert( img.type() == CV_16SC1 ); |
|
|
|
|
template <typename T> |
|
|
|
|
void filterSpecklesImpl(cv::Mat& img, int newVal, int maxSpeckleSize, int maxDiff, cv::Mat& _buf) |
|
|
|
|
{ |
|
|
|
|
using namespace cv; |
|
|
|
|
|
|
|
|
|
int newVal = cvRound(_newval); |
|
|
|
|
int maxDiff = cvRound(_maxDiff); |
|
|
|
|
int width = img.cols, height = img.rows, npixels = width*height; |
|
|
|
|
size_t bufSize = npixels*(int)(sizeof(Point2s) + sizeof(int) + sizeof(uchar)); |
|
|
|
|
if( !_buf.isContinuous() || !_buf.data || _buf.cols*_buf.rows*_buf.elemSize() < bufSize ) |
|
|
|
|
_buf.create(1, (int)bufSize, CV_8U); |
|
|
|
|
|
|
|
|
|
uchar* buf = _buf.data; |
|
|
|
|
int i, j, dstep = (int)(img.step/sizeof(short)); |
|
|
|
|
int i, j, dstep = (int)(img.step/sizeof(T)); |
|
|
|
|
int* labels = (int*)buf; |
|
|
|
|
buf += npixels*sizeof(labels[0]); |
|
|
|
|
Point2s* wbuf = (Point2s*)buf; |
|
|
|
@ -885,7 +883,7 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi |
|
|
|
|
|
|
|
|
|
for( i = 0; i < height; i++ ) |
|
|
|
|
{ |
|
|
|
|
short* ds = img.ptr<short>(i); |
|
|
|
|
T* ds = img.ptr<T>(i); |
|
|
|
|
int* ls = labels + width*i; |
|
|
|
|
|
|
|
|
|
for( j = 0; j < width; j++ ) |
|
|
|
@ -895,7 +893,7 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi |
|
|
|
|
if( ls[j] ) // has a label, check for bad label
|
|
|
|
|
{ |
|
|
|
|
if( rtype[ls[j]] ) // small region, zero out disparity
|
|
|
|
|
ds[j] = (short)newVal; |
|
|
|
|
ds[j] = (T)newVal; |
|
|
|
|
} |
|
|
|
|
// no label, assign and propagate
|
|
|
|
|
else |
|
|
|
@ -911,8 +909,8 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi |
|
|
|
|
{ |
|
|
|
|
count++; |
|
|
|
|
// put neighbors onto wavefront
|
|
|
|
|
short* dpp = &img.at<short>(p.y, p.x); |
|
|
|
|
short dp = *dpp; |
|
|
|
|
T* dpp = &img.at<T>(p.y, p.x); |
|
|
|
|
T dp = *dpp; |
|
|
|
|
int* lpp = labels + width*p.y + p.x; |
|
|
|
|
|
|
|
|
|
if( p.x < width-1 && !lpp[+1] && dpp[+1] != newVal && std::abs(dp - dpp[+1]) <= maxDiff ) |
|
|
|
@ -948,7 +946,7 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi |
|
|
|
|
if( count <= maxSpeckleSize ) // speckle region
|
|
|
|
|
{ |
|
|
|
|
rtype[ls[j]] = 1; // small region label
|
|
|
|
|
ds[j] = (short)newVal; |
|
|
|
|
ds[j] = (T)newVal; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
rtype[ls[j]] = 0; // large region label
|
|
|
|
@ -957,6 +955,23 @@ void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSi |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cv::filterSpeckles( InputOutputArray _img, double _newval, int maxSpeckleSize, |
|
|
|
|
double _maxDiff, InputOutputArray __buf ) |
|
|
|
|
{ |
|
|
|
|
Mat img = _img.getMat(); |
|
|
|
|
Mat temp, &_buf = __buf.needed() ? __buf.getMatRef() : temp; |
|
|
|
|
CV_Assert( img.type() == CV_8UC1 || img.type() == CV_16SC1 ); |
|
|
|
|
|
|
|
|
|
int newVal = cvRound(_newval); |
|
|
|
|
int maxDiff = cvRound(_maxDiff); |
|
|
|
|
|
|
|
|
|
if (img.type() == CV_8UC1) |
|
|
|
|
filterSpecklesImpl<uchar>(img, newVal, maxSpeckleSize, maxDiff, _buf); |
|
|
|
|
else |
|
|
|
|
filterSpecklesImpl<short>(img, newVal, maxSpeckleSize, maxDiff, _buf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cv::validateDisparity( InputOutputArray _disp, InputArray _cost, int minDisparity, |
|
|
|
|
int numberOfDisparities, int disp12MaxDiff ) |
|
|
|
|