Skip to content

Commit 2a8db6d

Browse files
add parallel_for_ to performThreshold
1 parent a98dcc7 commit 2a8db6d

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

modules/mcc/src/checker_detector.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -539,17 +539,18 @@ void CCheckerDetectorImpl::
539539
// number of window sizes (scales) to apply adaptive thresholding
540540
int nScales = (params->adaptiveThreshWinSizeMax - params->adaptiveThreshWinSizeMin) / params->adaptiveThreshWinSizeStep + 1;
541541
thresholdImgs.create(nScales, 1, CV_8U);
542-
std::vector<cv::Mat> _thresholdImgs;
543-
for (int i = 0; i < nScales; i++)
544-
{
545-
int currScale = params->adaptiveThreshWinSizeMin + i * params->adaptiveThreshWinSizeStep;
546-
547-
cv::Mat tempThresholdImg;
548-
cv::adaptiveThreshold(grayscaleImg, tempThresholdImg, 255, cv::ADAPTIVE_THRESH_MEAN_C,
549-
cv::THRESH_BINARY_INV, currScale, params->adaptiveThreshConstant);
550-
551-
_thresholdImgs.push_back(tempThresholdImg);
552-
}
542+
std::vector<cv::Mat> _thresholdImgs(nScales);
543+
parallel_for_(Range(0, nScales),[&](const Range& range) {
544+
const int start = range.start;
545+
const int end = range.end;
546+
for (int i = start; i < end; i++) {
547+
int currScale = params->adaptiveThreshWinSizeMin + i * params->adaptiveThreshWinSizeStep;
548+
cv::Mat tempThresholdImg;
549+
cv::adaptiveThreshold(grayscaleImg, tempThresholdImg, 255, ADAPTIVE_THRESH_MEAN_C,
550+
THRESH_BINARY_INV, currScale, params->adaptiveThreshConstant);
551+
_thresholdImgs[i] = tempThresholdImg;
552+
}
553+
});
553554

554555
thresholdImgs.assign(_thresholdImgs);
555556
}

0 commit comments

Comments
 (0)