I’m testing MCC module to correct colors of my images.
I was able to build/install the module, extract the Color Checker from an image and draw the patches on the image.
Now I want to get the regions (e.g. the 4 rectangle vertexes) of the color checker patches, drawn by the CCheckerDraw.
How to do it?
Looking at the source code, CCheckerDraw::draw function gets the region from CChartModel data, but CChartModel is not exposed in the DLL. And I don’t see any other object that exposes such info.
MCC test source has a runCCheckerDraw() function, that checks that the number of contours generated by draw() function are == to the number of expected patches. I can extract the region from said contours, but seems a lot of useless extra work.
Most examples and the tutorial just detect+draw the patches. I based my work on those examples.
color_correction_model.cpp seems to have something more interesting. Will look into it.
Sorry for the laaaate answer. Missed the notification.
I didn’t find an out-of-the-box OpenCV solution (as my perky comment suggests). Had to add some processing:
// Search color checker
Ptr<CCheckerDetector> checkerDetector = CCheckerDetector::create();
bool colorCheckerFound = checkerDetector->process(colorCheckerImage_, MCC24, 1);
if(!colorCheckerFound)
throw runtime_error("Color checker not found");
// Draw ROIs on an image and define region given contours
// I have no idea why I can't get region points directly...
cv::Mat img(colorCheckerImage_.rows, colorCheckerImage_.cols, CV_8UC3, {0, 0, 0});
Ptr<CCheckerDraw> cdraw = CCheckerDraw::create(checkerDetector->getListColorChecker()[0], CV_RGB(0, 250, 0), 1);
cdraw->draw(img);
vector<vector<Point>> contours;
vector<vector<Point>> patchesRoi;
cvtColor(img, img, COLOR_BGR2GRAY);
findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
for(unsigned int i = 0; i < contours.size(); i++)
{
vector<Point> roi;
double epsilon = 1;
while(roi.size() != 4)
{
approxPolyDP(contours[i], roi, epsilon, true);
epsilon++;
}
// Store ROIs in vector
patchesRoi.push_back(roi);
}