diff --git a/modules/mcc/src/checker_detector.cpp b/modules/mcc/src/checker_detector.cpp index b84c885d6e9..dcff0a25f3b 100644 --- a/modules/mcc/src/checker_detector.cpp +++ b/modules/mcc/src/checker_detector.cpp @@ -40,8 +40,6 @@ namespace cv namespace mcc { -std::mutex mtx; // mutex for critical section - Ptr CCheckerDetector::create() { return makePtr(); @@ -113,7 +111,7 @@ bool CCheckerDetectorImpl:: // Get chanels split(img_rgb_org, rgb_planes); split(img_ycbcr_org, ycbcr_planes); - + cv::Mutex mtx; parallel_for_( Range(0, (int)img_bw.size()), [&](const Range &range) { const int begin = range.start; @@ -237,9 +235,10 @@ bool CCheckerDetectorImpl:: for (cv::Point2f &corner : checker->getBox()) corner += static_cast(region.tl()); - mtx.lock(); // push_back is not thread safe - m_checkers.push_back(checker); - mtx.unlock(); + { + cv::AutoLock lock(mtx); + m_checkers.push_back(checker); + } } } #ifdef MCC_DEBUG @@ -332,7 +331,7 @@ bool CCheckerDetectorImpl:: cv::Mat3f img_rgb_f(img_bgr); cv::cvtColor(img_rgb_f, img_rgb_f, COLOR_BGR2RGB); img_rgb_f /= 255; - + cv::Mutex mtx; parallel_for_( Range(0, (int)img_bw.size()), [&](const Range &range) { const int begin = range.start; @@ -456,9 +455,11 @@ bool CCheckerDetectorImpl:: { for (cv::Point2f &corner : checker->getBox()) corner += static_cast(region.tl() + innerRegion.tl()); - mtx.lock(); // push_back is not thread safe - m_checkers.push_back(checker); - mtx.unlock(); + + { + cv::AutoLock lock(mtx); + m_checkers.push_back(checker); + } } } #ifdef MCC_DEBUG @@ -1236,7 +1237,7 @@ void CCheckerDetectorImpl:: // Create table charts information // |p_size|average|stddev|max|min| // RGB | | | | | | - // YCbCr | + // YCbCr | Mat _charts_rgb = cv::Mat(cv::Size(5, 3 * (int)N), CV_64F); Mat _charts_ycbcr = cv::Mat(cv::Size(5, 3 * (int)N), CV_64F); diff --git a/modules/mcc/src/precomp.hpp b/modules/mcc/src/precomp.hpp index 98f2891888c..349c8c08833 100644 --- a/modules/mcc/src/precomp.hpp +++ b/modules/mcc/src/precomp.hpp @@ -38,7 +38,6 @@ #include #include -#include // std::mutex #include "opencv2/mcc.hpp"