expanded cv::threshold parallelization to other threading frameworks; fixed potential bug with unprocessed bottom of the image; fixed build problem in stitching

This commit is contained in:
Vadim Pisarevsky 2012-10-09 22:38:04 +04:00
parent e365726c4a
commit 044d38a051
2 changed files with 16 additions and 19 deletions

View File

@ -661,7 +661,7 @@ getThreshVal_Otsu_8u( const Mat& _src )
return max_val; return max_val;
} }
class ThresholdRunner class ThresholdRunner : public ParallelLoopBody
{ {
public: public:
ThresholdRunner(Mat _src, Mat _dst, int _nStripes, double _thresh, double _maxval, int _thresholdType) ThresholdRunner(Mat _src, Mat _dst, int _nStripes, double _thresh, double _maxval, int _thresholdType)
@ -676,10 +676,11 @@ public:
thresholdType = _thresholdType; thresholdType = _thresholdType;
} }
void operator () ( const BlockedRange& range ) const void operator () ( const Range& range ) const
{ {
int row0 = std::min(cvRound(range.begin() * src.rows / nStripes), src.rows); int row0 = std::min(cvRound(range.start * src.rows / nStripes), src.rows);
int row1 = std::min(cvRound(range.end() * src.rows / nStripes), src.rows); int row1 = range.end >= nStripes ? src.rows :
std::min(cvRound(range.end * src.rows / nStripes), src.rows);
/*if(0) /*if(0)
printf("Size = (%d, %d), range[%d,%d), row0 = %d, row1 = %d\n", printf("Size = (%d, %d), range[%d,%d), row0 = %d, row1 = %d\n",
@ -756,12 +757,10 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
} }
else else
src.copyTo(dst); src.copyTo(dst);
return thresh;
} }
else thresh = ithresh;
{ maxval = imaxval;
parallel_for(BlockedRange(0, nStripes),
ThresholdRunner(src, dst, nStripes, (uchar)ithresh, (uchar)imaxval, type));
}
} }
else if( src.depth() == CV_16S ) else if( src.depth() == CV_16S )
{ {
@ -785,21 +784,18 @@ double cv::threshold( InputArray _src, OutputArray _dst, double thresh, double m
} }
else else
src.copyTo(dst); src.copyTo(dst);
return thresh;
} }
else thresh = ithresh;
{ maxval = imaxval;
parallel_for(BlockedRange(0, nStripes),
ThresholdRunner(src, dst, nStripes, (short)ithresh, (short)imaxval, type));
}
} }
else if( src.depth() == CV_32F ) else if( src.depth() == CV_32F )
{ ;
parallel_for(BlockedRange(0, nStripes),
ThresholdRunner(src, dst, nStripes, (float)thresh, (float)maxval, type));
}
else else
CV_Error( CV_StsUnsupportedFormat, "" ); CV_Error( CV_StsUnsupportedFormat, "" );
parallel_for_(Range(0, nStripes),
ThresholdRunner(src, dst, nStripes, thresh, maxval, type));
return thresh; return thresh;
} }

View File

@ -41,6 +41,7 @@
// //
//M*/ //M*/
#include <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include "opencv2/opencv_modules.hpp" #include "opencv2/opencv_modules.hpp"