Replaced most of the usages of parallel_for with that of parallel_for_.
This should allow many algorithms to take advantage of more parallelization technologies.
This commit is contained in:
@@ -214,7 +214,7 @@ static void keepStrongest( int N, vector<KeyPoint>& keypoints )
|
||||
}
|
||||
|
||||
namespace {
|
||||
class GridAdaptedFeatureDetectorInvoker
|
||||
class GridAdaptedFeatureDetectorInvoker : public ParallelLoopBody
|
||||
{
|
||||
private:
|
||||
int gridRows_, gridCols_;
|
||||
@@ -223,29 +223,24 @@ private:
|
||||
const Mat& image_;
|
||||
const Mat& mask_;
|
||||
const Ptr<FeatureDetector>& detector_;
|
||||
#ifdef HAVE_TBB
|
||||
tbb::mutex* kptLock_;
|
||||
#endif
|
||||
Mutex* kptLock_;
|
||||
|
||||
GridAdaptedFeatureDetectorInvoker& operator=(const GridAdaptedFeatureDetectorInvoker&); // to quiet MSVC
|
||||
|
||||
public:
|
||||
|
||||
GridAdaptedFeatureDetectorInvoker(const Ptr<FeatureDetector>& detector, const Mat& image, const Mat& mask, vector<KeyPoint>& keypoints, int maxPerCell, int gridRows, int gridCols
|
||||
#ifdef HAVE_TBB
|
||||
, tbb::mutex* kptLock
|
||||
#endif
|
||||
) : gridRows_(gridRows), gridCols_(gridCols), maxPerCell_(maxPerCell),
|
||||
keypoints_(keypoints), image_(image), mask_(mask), detector_(detector)
|
||||
#ifdef HAVE_TBB
|
||||
, kptLock_(kptLock)
|
||||
#endif
|
||||
GridAdaptedFeatureDetectorInvoker(const Ptr<FeatureDetector>& detector, const Mat& image, const Mat& mask,
|
||||
vector<KeyPoint>& keypoints, int maxPerCell, int gridRows, int gridCols,
|
||||
cv::Mutex* kptLock)
|
||||
: gridRows_(gridRows), gridCols_(gridCols), maxPerCell_(maxPerCell),
|
||||
keypoints_(keypoints), image_(image), mask_(mask), detector_(detector),
|
||||
kptLock_(kptLock)
|
||||
{
|
||||
}
|
||||
|
||||
void operator() (const BlockedRange& range) const
|
||||
void operator() (const Range& range) const
|
||||
{
|
||||
for (int i = range.begin(); i < range.end(); ++i)
|
||||
for (int i = range.start; i < range.end; ++i)
|
||||
{
|
||||
int celly = i / gridCols_;
|
||||
int cellx = i - celly * gridCols_;
|
||||
@@ -270,9 +265,8 @@ public:
|
||||
it->pt.x += col_range.start;
|
||||
it->pt.y += row_range.start;
|
||||
}
|
||||
#ifdef HAVE_TBB
|
||||
tbb::mutex::scoped_lock join_keypoints(*kptLock_);
|
||||
#endif
|
||||
|
||||
cv::AutoLock join_keypoints(*kptLock_);
|
||||
keypoints_.insert( keypoints_.end(), sub_keypoints.begin(), sub_keypoints.end() );
|
||||
}
|
||||
}
|
||||
@@ -289,13 +283,9 @@ void GridAdaptedFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>&
|
||||
keypoints.reserve(maxTotalKeypoints);
|
||||
int maxPerCell = maxTotalKeypoints / (gridRows * gridCols);
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
tbb::mutex kptLock;
|
||||
cv::parallel_for(cv::BlockedRange(0, gridRows * gridCols),
|
||||
cv::Mutex kptLock;
|
||||
cv::parallel_for_(cv::Range(0, gridRows * gridCols),
|
||||
GridAdaptedFeatureDetectorInvoker(detector, image, mask, keypoints, maxPerCell, gridRows, gridCols, &kptLock));
|
||||
#else
|
||||
GridAdaptedFeatureDetectorInvoker(detector, image, mask, keypoints, maxPerCell, gridRows, gridCols)(cv::BlockedRange(0, gridRows * gridCols));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user