Skip to content

Commit 2b3ddc0

Browse files
Merge pull request #3875 from gursimarsingh:mcc_pr3599_bugfix_5.xx
Fix bugs in checker_detector.cpp after resolving conflicts from PR #3599 #3875 ### This is the pull request for fixing some bugs in "Color Checker detection" + The link to pretrained tensorflow model for detecting Macbeth Color-checker: https://drive.google.com/drive/folders/1JNWlmyfZKxiYQoYk6f0RzcGtHuiZq1Pz #### 1, Detecting color-checker using Neural network When loading the pretrained Macbeth color-checker detector model, and set it successfully to CCheckerDetector, ``` Ptr<CCheckerDetector> detector = CCheckerDetector::create(); if (!detector->setNet(net)) { cout << "Loading Model failed: Aborting" << endl; return 0; } ``` then ``` if(!detector->process(image, cv::mcc::MCC24, color_checker_roi, 1, true, params)) { std::cout<<"Color-checker not found\n"; } Ptr<mcc::CChecker> checker = detector->getBestColorChecker(); Ptr<CCheckerDraw> cdraw = CCheckerDraw::create(checker); cdraw->draw(image); ``` + problem 1: cdraw function failed to draw the correct result due to the following code block failed to update box in checker: ``` for (Ptr<CChecker> checker : checkers){ for (cv::Point2f &corner : checker->getBox()) corner += static_cast<cv::Point2f>(region.tl() + innerRegion.tl()); ... } ``` the corrected and test pass version is: ``` for (Ptr<CChecker>& checker : checkers){ std::vector<cv::Point2f> restore_box; for (cv::Point2f& corner : checker->getBox()) { corner += static_cast<cv::Point2f>(region.tl() + innerRegion.tl()); restore_box.emplace_back(corner); } checker->setBox(restore_box); } ... ``` See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
1 parent ae38440 commit 2b3ddc0

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

modules/mcc/src/checker_detector.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,12 @@ bool CCheckerDetectorImpl::
232232
#endif
233233
for (Ptr<CChecker> checker : checkers)
234234
{
235-
for (cv::Point2f &corner : checker->getBox())
236-
corner += static_cast<cv::Point2f>(region.tl());
237-
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);
238241
{
239242
cv::AutoLock lock(mtx);
240243
m_checkers.push_back(checker);
@@ -453,9 +456,12 @@ bool CCheckerDetectorImpl::
453456
#endif
454457
for (Ptr<CChecker> checker : checkers)
455458
{
456-
for (cv::Point2f &corner : checker->getBox())
457-
corner += static_cast<cv::Point2f>(region.tl() + innerRegion.tl());
458-
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);
459465
{
460466
cv::AutoLock lock(mtx);
461467
m_checkers.push_back(checker);
@@ -1363,4 +1369,4 @@ float CCheckerDetectorImpl::
13631369
}
13641370

13651371
} // namespace mcc
1366-
} // namespace cv
1372+
} // namespace cv

0 commit comments

Comments
 (0)