Skip to content

Commit 56cf3e6

Browse files
authored
Merge pull request #3925 from gursimarsingh:mcc_bug_fix
[BUG FIX] Fix DNN-based MCC checker detector's checker box alignment issue
2 parents 09d9e0d + 6fb4508 commit 56cf3e6

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

modules/mcc/src/checker_detector.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ bool CCheckerDetectorImpl::
217217
// checker color analysis
218218
//-------------------------------------------------------------------
219219
std::vector<Ptr<CChecker>> checkers;
220+
Point2f total_offset = static_cast<Point2f>(region.tl());
220221
checkerAnalysis(img_rgb_f, chartType, nc, colorCharts, checkers, asp, params,
221-
img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes);
222+
img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes, total_offset);
222223

223224
#ifdef MCC_DEBUG
224225
cv::Mat image_checker;
@@ -232,16 +233,8 @@ bool CCheckerDetectorImpl::
232233
#endif
233234
for (Ptr<CChecker> checker : checkers)
234235
{
235-
const std::vector<cv::Point2f>& checkerBox = checker->getBox();
236-
std::vector<cv::Point2f> restore_box(checkerBox.size());
237-
for (size_t a = 0; a < checkerBox.size(); ++a) {
238-
restore_box[a] = checkerBox[a] + static_cast<cv::Point2f>(region.tl());
239-
}
240-
checker->setBox(restore_box);
241-
{
242-
cv::AutoLock lock(mtx);
243-
m_checkers.push_back(checker);
244-
}
236+
cv::AutoLock lock(mtx);
237+
m_checkers.push_back(checker);
245238
}
246239
}
247240
#ifdef MCC_DEBUG
@@ -442,8 +435,9 @@ bool CCheckerDetectorImpl::
442435
// checker color analysis
443436
//-------------------------------------------------------------------
444437
std::vector<Ptr<CChecker>> checkers;
438+
Point2f total_offset = static_cast<Point2f>(region.tl() + innerRegion.tl());
445439
checkerAnalysis(img_rgb_f, chartType, nc, colorCharts, checkers, asp, params,
446-
img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes);
440+
img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes, total_offset);
447441
#ifdef MCC_DEBUG
448442
cv::Mat image_checker;
449443
innerCroppedImage.copyTo(image_checker);
@@ -456,16 +450,8 @@ bool CCheckerDetectorImpl::
456450
#endif
457451
for (Ptr<CChecker> checker : checkers)
458452
{
459-
const std::vector<cv::Point2f>& checkerBox = checker->getBox();
460-
std::vector<cv::Point2f> restore_box(checkerBox.size());
461-
for (size_t a = 0; a < checkerBox.size(); ++a) {
462-
restore_box[a] = checkerBox[a] + static_cast<cv::Point2f>(region.tl() + innerRegion.tl());
463-
}
464-
checker->setBox(restore_box);
465-
{
466-
cv::AutoLock lock(mtx);
467-
m_checkers.push_back(checker);
468-
}
453+
cv::AutoLock lock(mtx);
454+
m_checkers.push_back(checker);
469455
}
470456
}
471457
#ifdef MCC_DEBUG
@@ -983,7 +969,8 @@ void CCheckerDetectorImpl::
983969
const cv::Mat &img_rgb_org,
984970
const cv::Mat &img_ycbcr_org,
985971
std::vector<cv::Mat> &rgb_planes,
986-
std::vector<cv::Mat> &ycbcr_planes)
972+
std::vector<cv::Mat> &ycbcr_planes,
973+
const Point2f& offset)
987974
{
988975
size_t N;
989976
std::vector<cv::Point2f> ibox;
@@ -1019,9 +1006,9 @@ void CCheckerDetectorImpl::
10191006
if (J[i] > params->maxError)
10201007
continue;
10211008

1022-
// redimention box
1009+
// redimension box
10231010
for (size_t j = 0; j < 4; j++)
1024-
ibox[j] = invAsp * ibox[j];
1011+
ibox[j] = invAsp * ibox[j] + offset;
10251012

10261013
cv::Mat charts_rgb, charts_ycbcr;
10271014
get_profile(ibox, chartType, charts_rgb, charts_ycbcr, img_rgb_org,

modules/mcc/src/checker_detector.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ class CCheckerDetectorImpl : public CCheckerDetector
151151
const cv::Mat &img_rgb_org,
152152
const cv::Mat &img_ycbcr_org,
153153
std::vector<cv::Mat> &rgb_planes,
154-
std::vector<cv::Mat> &ycbcr_planes);
154+
std::vector<cv::Mat> &ycbcr_planes,
155+
const Point2f& offset);
155156

156157
virtual void
157158
removeTooCloseDetections(const Ptr<DetectorParameters> &params);

0 commit comments

Comments
 (0)