opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

#Macbeth Chart detection Bugs#

Open Zorcius opened this issue 2 years ago • 1 comments

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);
}
...
  • problem 2: The computing results of color charts is not desired. Since, in the folloing code block, img_rgb_f is the cropped image by the rect result from Macbeth color-checker detector model, while img_rgb_org is the original image, thus colorCharts is gibberish and color correction is failed.
...
std::vector<Ptr<CChecker>> checkers;
checkerAnalysis(img_rgb_f, chartType, nc, colorCharts, checkers, asp, params,
                          img_rgb_org, img_ycbcr_org, rgb_planes, ycbcr_planes);
...

2, Detecting color-checker using basic algorithm

problem 1 is reproduced only by setting the color-roi region

if(!detector->process(image, cv::mcc::MCC24, color_roi_region, 1, false, params)) {
        std::cout<<"Color-checker not found\n";
 }

Pull Request Readiness Checklist

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
  • [ ] There is a reference to the original bug report and related work
  • [ ] 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

Zorcius avatar Nov 24 '23 10:11 Zorcius