Skip to content

Commit 6b5142f

Browse files
author
Alexander Panov
authored
Merge pull request #3647 from AleksandrPanov:add_to_mcc_detect_and_infer_test
Add to mcc detect and infer test #3647 merge with opencv/opencv_extra#1153 Added a full pipeline tests: 1. detector->process(img, (TYPECHART)0, 1, true); 2. ColorCorrectionModel model(src, COLORCHECKER_Macbeth); model.run(); 3. calibratedImage = model.infer(calibratedImage)*255.; ### 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 - [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. - [ ] The feature is well documented and sample code can be built with the project CMake
1 parent 1aaf6e1 commit 6b5142f

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

modules/mcc/src/checker_detector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ void CCheckerDetectorImpl::
511511
if (params->minImageSize > min_size)
512512
{
513513
aspOut = (float)params->minImageSize / min_size;
514-
cv::resize(bgr, bgrOut, cv::Size(int(size.width * aspOut), int(size.height * aspOut)));
514+
cv::resize(bgr, bgrOut, cv::Size(int(size.width * aspOut), int(size.height * aspOut)), INTER_LINEAR_EXACT);
515515
}
516516

517517
// Convert to grayscale

modules/mcc/test/test_mcc.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,101 @@ TEST(CV_mccRunCCheckerDetectorBasic, accuracy_VINYL18)
8181
runCCheckerDetectorBasic("VINYL18.png", VINYL18);
8282
}
8383

84+
TEST(CV_mcc_ccm_test, detect_Macbeth)
85+
{
86+
string path = cvtest::findDataFile("mcc/mcc_ccm_test.jpg");
87+
Mat img = imread(path, IMREAD_COLOR);
88+
Ptr<CCheckerDetector> detector = CCheckerDetector::create();
89+
90+
// detect MCC24 board
91+
ASSERT_TRUE(detector->process(img, MCC24, 1, false));
92+
93+
// read gold Macbeth corners
94+
path = cvtest::findDataFile("mcc/mcc_ccm_test.yml");
95+
FileStorage fs(path, FileStorage::READ);
96+
ASSERT_TRUE(fs.isOpened());
97+
FileNode node = fs["Macbeth_corners"];
98+
ASSERT_FALSE(node.empty());
99+
vector<Point2f> gold_corners;
100+
node >> gold_corners;
101+
Ptr<CChecker> checker = detector->getBestColorChecker();
102+
103+
// check Macbeth corners
104+
vector<Point2f> corners = checker->getBox();
105+
EXPECT_MAT_NEAR(gold_corners, corners, 3.6); // diff 3.57385 in ARM only
106+
107+
// read gold chartsRGB
108+
node = fs["chartsRGB"];
109+
Mat goldChartsRGB;
110+
node >> goldChartsRGB;
111+
fs.release();
112+
113+
// check chartsRGB
114+
Mat chartsRGB = checker->getChartsRGB();
115+
EXPECT_MAT_NEAR(goldChartsRGB.col(1), chartsRGB.col(1), 0.25); // diff 0.240634 in ARM only
116+
}
117+
118+
TEST(CV_mcc_ccm_test, compute_ccm)
119+
{
120+
// read gold chartsRGB
121+
string path = cvtest::findDataFile("mcc/mcc_ccm_test.yml");
122+
FileStorage fs(path, FileStorage::READ);
123+
Mat chartsRGB;
124+
FileNode node = fs["chartsRGB"];
125+
node >> chartsRGB;
126+
127+
// compute CCM
128+
ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth);
129+
model.run();
130+
131+
// read gold CCM
132+
node = fs["ccm"];
133+
ASSERT_FALSE(node.empty());
134+
Mat gold_ccm;
135+
node >> gold_ccm;
136+
fs.release();
137+
138+
// check CCM
139+
Mat ccm = model.getCCM();
140+
EXPECT_MAT_NEAR(gold_ccm, ccm, 1e-8);
141+
142+
const double gold_loss = 4.6386569120323129;
143+
// check loss
144+
const double loss = model.getLoss();
145+
EXPECT_NEAR(gold_loss, loss, 1e-8);
146+
}
147+
148+
TEST(CV_mcc_ccm_test, infer)
149+
{
150+
string path = cvtest::findDataFile("mcc/mcc_ccm_test.jpg");
151+
Mat img = imread(path, IMREAD_COLOR);
152+
// read gold calibrate img
153+
path = cvtest::findDataFile("mcc/mcc_ccm_test_res.png");
154+
Mat gold_img = imread(path);
155+
156+
// read gold chartsRGB
157+
path = cvtest::findDataFile("mcc/mcc_ccm_test.yml");
158+
FileStorage fs(path, FileStorage::READ);
159+
Mat chartsRGB;
160+
FileNode node = fs["chartsRGB"];
161+
node >> chartsRGB;
162+
fs.release();
163+
164+
// compute CCM
165+
ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth);
166+
model.run();
167+
168+
// compute calibrate image
169+
Mat calibratedImage;
170+
cvtColor(img, calibratedImage, COLOR_BGR2RGB);
171+
calibratedImage.convertTo(calibratedImage, CV_64F, 1. / 255.);
172+
calibratedImage = model.infer(calibratedImage);
173+
calibratedImage.convertTo(calibratedImage, CV_8UC3, 255.);
174+
cvtColor(calibratedImage, calibratedImage, COLOR_RGB2BGR);
175+
// check calibrated image
176+
EXPECT_MAT_NEAR(gold_img, calibratedImage, 0.1);
177+
}
178+
179+
84180
} // namespace
85181
} // namespace opencv_test

0 commit comments

Comments
 (0)