From 6fb4508cb908a56c27222fc6b79da67b3f6e42b5 Mon Sep 17 00:00:00 2001 From: Gursimar Singh Date: Thu, 10 Apr 2025 16:13:56 +0530 Subject: [PATCH] mcc bug fix --- modules/mcc/src/checker_detector.cpp | 37 +++++++++------------------- modules/mcc/src/checker_detector.hpp | 3 ++- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/modules/mcc/src/checker_detector.cpp b/modules/mcc/src/checker_detector.cpp index a7d624e15a6..f2f8267a202 100644 --- a/modules/mcc/src/checker_detector.cpp +++ b/modules/mcc/src/checker_detector.cpp @@ -217,8 +217,9 @@ bool CCheckerDetectorImpl:: // checker color analysis //------------------------------------------------------------------- std::vector> checkers; + Point2f total_offset = static_cast(region.tl()); checkerAnalysis(img_rgb_f, chartType, nc, colorCharts, checkers, asp, params, - img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes); + img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes, total_offset); #ifdef MCC_DEBUG cv::Mat image_checker; @@ -232,16 +233,8 @@ bool CCheckerDetectorImpl:: #endif for (Ptr checker : checkers) { - const std::vector& checkerBox = checker->getBox(); - std::vector restore_box(checkerBox.size()); - for (size_t a = 0; a < checkerBox.size(); ++a) { - restore_box[a] = checkerBox[a] + static_cast(region.tl()); - } - checker->setBox(restore_box); - { - cv::AutoLock lock(mtx); - m_checkers.push_back(checker); - } + cv::AutoLock lock(mtx); + m_checkers.push_back(checker); } } #ifdef MCC_DEBUG @@ -442,8 +435,9 @@ bool CCheckerDetectorImpl:: // checker color analysis //------------------------------------------------------------------- std::vector> checkers; + Point2f total_offset = static_cast(region.tl() + innerRegion.tl()); checkerAnalysis(img_rgb_f, chartType, nc, colorCharts, checkers, asp, params, - img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes); + img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes, total_offset); #ifdef MCC_DEBUG cv::Mat image_checker; innerCroppedImage.copyTo(image_checker); @@ -456,16 +450,8 @@ bool CCheckerDetectorImpl:: #endif for (Ptr checker : checkers) { - const std::vector& checkerBox = checker->getBox(); - std::vector restore_box(checkerBox.size()); - for (size_t a = 0; a < checkerBox.size(); ++a) { - restore_box[a] = checkerBox[a] + static_cast(region.tl() + innerRegion.tl()); - } - checker->setBox(restore_box); - { - cv::AutoLock lock(mtx); - m_checkers.push_back(checker); - } + cv::AutoLock lock(mtx); + m_checkers.push_back(checker); } } #ifdef MCC_DEBUG @@ -983,7 +969,8 @@ void CCheckerDetectorImpl:: const cv::Mat &img_rgb_org, const cv::Mat &img_ycbcr_org, std::vector &rgb_planes, - std::vector &ycbcr_planes) + std::vector &ycbcr_planes, + const Point2f& offset) { size_t N; std::vector ibox; @@ -1019,9 +1006,9 @@ void CCheckerDetectorImpl:: if (J[i] > params->maxError) continue; - // redimention box + // redimension box for (size_t j = 0; j < 4; j++) - ibox[j] = invAsp * ibox[j]; + ibox[j] = invAsp * ibox[j] + offset; cv::Mat charts_rgb, charts_ycbcr; get_profile(ibox, chartType, charts_rgb, charts_ycbcr, img_rgb_org, diff --git a/modules/mcc/src/checker_detector.hpp b/modules/mcc/src/checker_detector.hpp index 4c922b5d1d4..7d7ad66799c 100644 --- a/modules/mcc/src/checker_detector.hpp +++ b/modules/mcc/src/checker_detector.hpp @@ -151,7 +151,8 @@ class CCheckerDetectorImpl : public CCheckerDetector const cv::Mat &img_rgb_org, const cv::Mat &img_ycbcr_org, std::vector &rgb_planes, - std::vector &ycbcr_planes); + std::vector &ycbcr_planes, + const Point2f& offset); virtual void removeTooCloseDetections(const Ptr ¶ms);