@@ -81,5 +81,54 @@ TEST(CV_mccRunCCheckerDetectorBasic, accuracy_VINYL18)
8181 runCCheckerDetectorBasic (" VINYL18.png" , VINYL18);
8282}
8383
84+ TEST (CV_mcc_ccm_test, detectAndInfer)
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, (TYPECHART)0 , 1 , true ));
92+
93+ // read gold CCM
94+ path = cvtest::findDataFile (" mcc/mcc_ccm_test.yml" );
95+ FileStorage fs (path, FileStorage::READ);
96+ ASSERT_TRUE (fs.isOpened ());
97+ FileNode node = fs[" ccm" ];
98+ ASSERT_FALSE (node.empty ());
99+ Mat gold_ccm;
100+ node >> gold_ccm;
101+ fs.release ();
102+
103+ // compute CCM
104+ Ptr<CChecker> checker = detector->getBestColorChecker ();
105+ Mat chartsRGB = checker->getChartsRGB ();
106+ Mat src = chartsRGB.col (1 ).clone ().reshape (3 , chartsRGB.rows /3 ) / 255 .;
107+ ColorCorrectionModel model (src, COLORCHECKER_Macbeth);
108+ model.run ();
109+ Mat ccm = model.getCCM ();
110+ // check CCM
111+ ASSERT_MAT_NEAR (gold_ccm, ccm, 1e-12 );
112+
113+ const double gold_loss = 4.6386569120323129 ;
114+ const double loss = model.getLoss ();
115+ // check loss
116+ EXPECT_NEAR (gold_loss, loss, 1e-12 );
117+
118+ // read gold calibrate img
119+ path = cvtest::findDataFile (" mcc/mcc_ccm_test_res.png" );
120+ Mat gold_img = imread (path);
121+
122+ // compute calibrate image
123+ Mat calibratedImage;
124+ cvtColor (img, calibratedImage, COLOR_BGR2RGB);
125+ calibratedImage.convertTo (calibratedImage, CV_64F, 1 . / 255 .);
126+ calibratedImage = model.infer (calibratedImage)*255 .;
127+ calibratedImage.convertTo (calibratedImage, CV_8UC3);
128+ cvtColor (calibratedImage, calibratedImage, COLOR_RGB2BGR);
129+ // check calibrated image
130+ EXPECT_MAT_NEAR (gold_img, calibratedImage, 1e-12 );
131+ }
132+
84133} // namespace
85134} // namespace opencv_test
0 commit comments