@@ -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, 1e-8 );
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, chartsRGB, 1e-8 );
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