From 45027c4683f137f622573b3c6e73d8b5c48e01da Mon Sep 17 00:00:00 2001 From: Gursimar Singh Date: Mon, 3 Mar 2025 18:45:35 +0530 Subject: [PATCH] Separated mcc and ccm modules --- modules/ccm/CMakeLists.txt | 12 ++++ .../mcc => ccm/include/opencv2}/ccm.hpp | 7 ++- modules/ccm/perf/perf_ccm.cpp | 41 ++++++++++++ modules/ccm/perf/perf_main.cpp | 3 + modules/ccm/perf/perf_precomp.hpp | 13 ++++ .../samples/color_correction_model.cpp | 4 +- modules/{mcc => ccm}/src/ccm.cpp | 2 +- modules/{mcc => ccm}/src/color.cpp | 0 modules/{mcc => ccm}/src/color.hpp | 6 +- modules/{mcc => ccm}/src/colorspace.cpp | 0 modules/{mcc => ccm}/src/colorspace.hpp | 6 +- modules/{mcc => ccm}/src/distance.cpp | 0 modules/{mcc => ccm}/src/distance.hpp | 6 +- modules/{mcc => ccm}/src/io.cpp | 0 modules/{mcc => ccm}/src/io.hpp | 4 +- modules/{mcc => ccm}/src/linearize.cpp | 0 modules/{mcc => ccm}/src/linearize.hpp | 6 +- modules/{mcc => ccm}/src/operations.cpp | 0 modules/{mcc => ccm}/src/operations.hpp | 4 +- modules/ccm/src/precomp.hpp | 44 +++++++++++++ modules/{mcc => ccm}/src/utils.cpp | 0 modules/{mcc => ccm}/src/utils.hpp | 4 +- modules/{mcc => ccm}/test/test_ccm.cpp | 61 ++++++++++++++++++ modules/ccm/test/test_main.cpp | 7 +++ modules/ccm/test/test_precomp.hpp | 17 +++++ .../basic_ccm/color_correction_model.markdown | 6 +- .../tutorials/table_of_content_ccm.markdown | 0 modules/mcc/include/opencv2/mcc.hpp | 7 +-- modules/mcc/perf/perf_mcc.cpp | 24 ------- modules/mcc/perf/perf_precomp.hpp | 1 - modules/mcc/test/test_mcc.cpp | 62 ------------------- modules/mcc/test/test_precomp.hpp | 2 - 32 files changed, 227 insertions(+), 122 deletions(-) create mode 100644 modules/ccm/CMakeLists.txt rename modules/{mcc/include/opencv2/mcc => ccm/include/opencv2}/ccm.hpp (99%) create mode 100644 modules/ccm/perf/perf_ccm.cpp create mode 100644 modules/ccm/perf/perf_main.cpp create mode 100644 modules/ccm/perf/perf_precomp.hpp rename modules/{mcc => ccm}/samples/color_correction_model.cpp (98%) rename modules/{mcc => ccm}/src/ccm.cpp (99%) rename modules/{mcc => ccm}/src/color.cpp (100%) rename modules/{mcc => ccm}/src/color.hpp (97%) rename modules/{mcc => ccm}/src/colorspace.cpp (100%) rename modules/{mcc => ccm}/src/colorspace.hpp (98%) rename modules/{mcc => ccm}/src/distance.cpp (100%) rename modules/{mcc => ccm}/src/distance.hpp (96%) rename modules/{mcc => ccm}/src/io.cpp (100%) rename modules/{mcc => ccm}/src/io.hpp (96%) rename modules/{mcc => ccm}/src/linearize.cpp (100%) rename modules/{mcc => ccm}/src/linearize.hpp (97%) rename modules/{mcc => ccm}/src/operations.cpp (100%) rename modules/{mcc => ccm}/src/operations.hpp (97%) create mode 100644 modules/ccm/src/precomp.hpp rename modules/{mcc => ccm}/src/utils.cpp (100%) rename modules/{mcc => ccm}/src/utils.hpp (98%) rename modules/{mcc => ccm}/test/test_ccm.cpp (78%) create mode 100644 modules/ccm/test/test_main.cpp create mode 100644 modules/ccm/test/test_precomp.hpp rename modules/{mcc => ccm}/tutorials/basic_ccm/color_correction_model.markdown (96%) rename modules/{mcc => ccm}/tutorials/table_of_content_ccm.markdown (100%) diff --git a/modules/ccm/CMakeLists.txt b/modules/ccm/CMakeLists.txt new file mode 100644 index 000000000..20d08bfeb --- /dev/null +++ b/modules/ccm/CMakeLists.txt @@ -0,0 +1,12 @@ +set(the_description "Color Correction Module") +ocv_define_module(ccm + opencv_core + opencv_imgproc + opencv_3d + opencv_dnn + opencv_mcc + WRAP + python +) +add_dependencies(opencv_ccm opencv_mcc) +include_directories(${OPENCV_EXTRA_MODULES_PATH}/modules/mcc/include) diff --git a/modules/mcc/include/opencv2/mcc/ccm.hpp b/modules/ccm/include/opencv2/ccm.hpp similarity index 99% rename from modules/mcc/include/opencv2/mcc/ccm.hpp rename to modules/ccm/include/opencv2/ccm.hpp index a3686db47..b44ac657a 100644 --- a/modules/mcc/include/opencv2/mcc/ccm.hpp +++ b/modules/ccm/include/opencv2/ccm.hpp @@ -25,8 +25,8 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_CCM_HPP__ -#define __OPENCV_MCC_CCM_HPP__ +#ifndef __OPENCV_CCM_HPP__ +#define __OPENCV_CCM_HPP__ #include #include @@ -35,7 +35,8 @@ namespace cv { namespace ccm { -/** @addtogroup color_correction + +/** @defgroup ccm Color Correction module @{ Introduction diff --git a/modules/ccm/perf/perf_ccm.cpp b/modules/ccm/perf/perf_ccm.cpp new file mode 100644 index 000000000..0d523e347 --- /dev/null +++ b/modules/ccm/perf/perf_ccm.cpp @@ -0,0 +1,41 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "perf_precomp.hpp" +#include "opencv2/ccm.hpp" + +namespace opencv_test +{ +namespace +{ + +using namespace std; +using namespace cv::ccm; + +PERF_TEST(CV_mcc_perf, infer) { + // read gold chartsRGB + string path = cvtest::findDataFile("cv/mcc/mcc_ccm_test.yml"); + FileStorage fs(path, FileStorage::READ); + Mat chartsRGB; + FileNode node = fs["chartsRGB"]; + node >> chartsRGB; + fs.release(); + + // compute CCM + ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth); + model.run(); + + Mat img(1000, 4000, CV_8UC3); + randu(img, 0, 255); + img.convertTo(img, CV_64F, 1. / 255.); + + TEST_CYCLE() { + model.infer(img); + } + + SANITY_CHECK_NOTHING(); +} + +} // namespace +} // namespace opencv_test diff --git a/modules/ccm/perf/perf_main.cpp b/modules/ccm/perf/perf_main.cpp new file mode 100644 index 000000000..a5b36b669 --- /dev/null +++ b/modules/ccm/perf/perf_main.cpp @@ -0,0 +1,3 @@ +#include "perf_precomp.hpp" + +CV_PERF_TEST_MAIN(ccm) diff --git a/modules/ccm/perf/perf_precomp.hpp b/modules/ccm/perf/perf_precomp.hpp new file mode 100644 index 000000000..e494ddca5 --- /dev/null +++ b/modules/ccm/perf/perf_precomp.hpp @@ -0,0 +1,13 @@ +#ifndef __OPENCV_PERF_PRECOMP_HPP__ +#define __OPENCV_PERF_PRECOMP_HPP__ + +#include "opencv2/ts.hpp" +#include "opencv2/ccm.hpp" + +namespace opencv_test +{ +using namespace cv::ccm; +using namespace perf; +} + +#endif diff --git a/modules/mcc/samples/color_correction_model.cpp b/modules/ccm/samples/color_correction_model.cpp similarity index 98% rename from modules/mcc/samples/color_correction_model.cpp rename to modules/ccm/samples/color_correction_model.cpp index 20df70437..b81229b00 100644 --- a/modules/mcc/samples/color_correction_model.cpp +++ b/modules/ccm/samples/color_correction_model.cpp @@ -4,13 +4,13 @@ #include #include #include +#include #include using namespace std; using namespace cv; using namespace mcc; using namespace ccm; -using namespace std; const char *about = "Basic chart detection"; const char *keys = @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) //compte color correction matrix //! [get_ccm_Matrix] - ColorCorrectionModel model1(src, COLORCHECKER_Vinyl); + ColorCorrectionModel model1(src, COLORCHECKER_Macbeth); model1.run(); Mat ccm = model1.getCCM(); std::cout<<"ccm "< // Chenqi Shan -#include "opencv2/mcc/ccm.hpp" +#include "opencv2/ccm.hpp" #include "linearize.hpp" namespace cv { namespace ccm { diff --git a/modules/mcc/src/color.cpp b/modules/ccm/src/color.cpp similarity index 100% rename from modules/mcc/src/color.cpp rename to modules/ccm/src/color.cpp diff --git a/modules/mcc/src/color.hpp b/modules/ccm/src/color.hpp similarity index 97% rename from modules/mcc/src/color.hpp rename to modules/ccm/src/color.hpp index 57ead3558..858fd4280 100644 --- a/modules/mcc/src/color.hpp +++ b/modules/ccm/src/color.hpp @@ -25,12 +25,12 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_COLOR_HPP__ -#define __OPENCV_MCC_COLOR_HPP__ +#ifndef __OPENCV_CCM_COLOR_HPP__ +#define __OPENCV_CCM_COLOR_HPP__ #include "distance.hpp" #include "colorspace.hpp" -#include "opencv2/mcc/ccm.hpp" +#include "opencv2/ccm.hpp" namespace cv { namespace ccm { diff --git a/modules/mcc/src/colorspace.cpp b/modules/ccm/src/colorspace.cpp similarity index 100% rename from modules/mcc/src/colorspace.cpp rename to modules/ccm/src/colorspace.cpp diff --git a/modules/mcc/src/colorspace.hpp b/modules/ccm/src/colorspace.hpp similarity index 98% rename from modules/mcc/src/colorspace.hpp rename to modules/ccm/src/colorspace.hpp index 572fea387..f4e70c36d 100644 --- a/modules/mcc/src/colorspace.hpp +++ b/modules/ccm/src/colorspace.hpp @@ -25,12 +25,12 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_COLORSPACE_HPP__ -#define __OPENCV_MCC_COLORSPACE_HPP__ +#ifndef __OPENCV_CCM_COLORSPACE_HPP__ +#define __OPENCV_CCM_COLORSPACE_HPP__ #include "operations.hpp" #include "io.hpp" -#include "opencv2/mcc/ccm.hpp" +#include "opencv2/ccm.hpp" namespace cv { namespace ccm { diff --git a/modules/mcc/src/distance.cpp b/modules/ccm/src/distance.cpp similarity index 100% rename from modules/mcc/src/distance.cpp rename to modules/ccm/src/distance.cpp diff --git a/modules/mcc/src/distance.hpp b/modules/ccm/src/distance.hpp similarity index 96% rename from modules/mcc/src/distance.hpp rename to modules/ccm/src/distance.hpp index 5acfc93cd..0fbc53377 100644 --- a/modules/mcc/src/distance.hpp +++ b/modules/ccm/src/distance.hpp @@ -25,11 +25,11 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_DISTANCE_HPP__ -#define __OPENCV_MCC_DISTANCE_HPP__ +#ifndef __OPENCV_CCM_DISTANCE_HPP__ +#define __OPENCV_CCM_DISTANCE_HPP__ #include "utils.hpp" -#include "opencv2/mcc/ccm.hpp" +#include "opencv2/ccm.hpp" namespace cv { namespace ccm { diff --git a/modules/mcc/src/io.cpp b/modules/ccm/src/io.cpp similarity index 100% rename from modules/mcc/src/io.cpp rename to modules/ccm/src/io.cpp diff --git a/modules/mcc/src/io.hpp b/modules/ccm/src/io.hpp similarity index 96% rename from modules/mcc/src/io.hpp rename to modules/ccm/src/io.hpp index c79864e3c..4fa9dce46 100644 --- a/modules/mcc/src/io.hpp +++ b/modules/ccm/src/io.hpp @@ -25,8 +25,8 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_IO_HPP__ -#define __OPENCV_MCC_IO_HPP__ +#ifndef __OPENCV_CCM_IO_HPP__ +#define __OPENCV_CCM_IO_HPP__ #include #include diff --git a/modules/mcc/src/linearize.cpp b/modules/ccm/src/linearize.cpp similarity index 100% rename from modules/mcc/src/linearize.cpp rename to modules/ccm/src/linearize.cpp diff --git a/modules/mcc/src/linearize.hpp b/modules/ccm/src/linearize.hpp similarity index 97% rename from modules/mcc/src/linearize.hpp rename to modules/ccm/src/linearize.hpp index a703b5c52..7f5d516dc 100644 --- a/modules/mcc/src/linearize.hpp +++ b/modules/ccm/src/linearize.hpp @@ -25,13 +25,13 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_LINEARIZE_HPP__ -#define __OPENCV_MCC_LINEARIZE_HPP__ +#ifndef __OPENCV_CCM_LINEARIZE_HPP__ +#define __OPENCV_CCM_LINEARIZE_HPP__ #include #include #include "color.hpp" -#include "opencv2/mcc/ccm.hpp" +#include "opencv2/ccm.hpp" namespace cv { namespace ccm { diff --git a/modules/mcc/src/operations.cpp b/modules/ccm/src/operations.cpp similarity index 100% rename from modules/mcc/src/operations.cpp rename to modules/ccm/src/operations.cpp diff --git a/modules/mcc/src/operations.hpp b/modules/ccm/src/operations.hpp similarity index 97% rename from modules/mcc/src/operations.hpp rename to modules/ccm/src/operations.hpp index ae3b39b60..994c4b1c3 100644 --- a/modules/mcc/src/operations.hpp +++ b/modules/ccm/src/operations.hpp @@ -25,8 +25,8 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_OPERATIONS_HPP__ -#define __OPENCV_MCC_OPERATIONS_HPP__ +#ifndef __OPENCV_CCM_OPERATIONS_HPP__ +#define __OPENCV_CCM_OPERATIONS_HPP__ #include "utils.hpp" diff --git a/modules/ccm/src/precomp.hpp b/modules/ccm/src/precomp.hpp new file mode 100644 index 000000000..7873bb39e --- /dev/null +++ b/modules/ccm/src/precomp.hpp @@ -0,0 +1,44 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +/* + * MIT License + * + * Copyright (c) 2018 Pedro Diamel Marrero Fernández + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef _CCM_PRECOMP_HPP +#define _CCM_PRECOMP_HPP + +#include + +#include +#include +#include +#include + +#include +#include + +#include "opencv2/ccm.hpp" + +#endif //_MCC_PRECOMP_HPP diff --git a/modules/mcc/src/utils.cpp b/modules/ccm/src/utils.cpp similarity index 100% rename from modules/mcc/src/utils.cpp rename to modules/ccm/src/utils.cpp diff --git a/modules/mcc/src/utils.hpp b/modules/ccm/src/utils.hpp similarity index 98% rename from modules/mcc/src/utils.hpp rename to modules/ccm/src/utils.hpp index 07ca65cb9..c7823c8b7 100644 --- a/modules/mcc/src/utils.hpp +++ b/modules/ccm/src/utils.hpp @@ -25,8 +25,8 @@ // Jinheng Zhang // Chenqi Shan -#ifndef __OPENCV_MCC_UTILS_HPP__ -#define __OPENCV_MCC_UTILS_HPP__ +#ifndef __OPENCV_CCM_UTILS_HPP__ +#define __OPENCV_CCM_UTILS_HPP__ #include diff --git a/modules/mcc/test/test_ccm.cpp b/modules/ccm/test/test_ccm.cpp similarity index 78% rename from modules/mcc/test/test_ccm.cpp rename to modules/ccm/test/test_ccm.cpp index cd6498f1b..71bd5b7c5 100644 --- a/modules/mcc/test/test_ccm.cpp +++ b/modules/ccm/test/test_ccm.cpp @@ -162,5 +162,66 @@ TEST(CV_ccmRunColorCorrection, test_masks_weights_2) ASSERT_MAT_NEAR(model2.getMask(), mask, 0.0); } +TEST(CV_mcc_ccm_test, compute_ccm) +{ + // read gold chartsRGB + string path = cvtest::findDataFile("mcc/mcc_ccm_test.yml"); + FileStorage fs(path, FileStorage::READ); + Mat chartsRGB; + FileNode node = fs["chartsRGB"]; + node >> chartsRGB; + + // compute CCM + ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth); + model.run(); + + // read gold CCM + node = fs["ccm"]; + ASSERT_FALSE(node.empty()); + Mat gold_ccm; + node >> gold_ccm; + fs.release(); + + // check CCM + Mat ccm = model.getCCM(); + EXPECT_MAT_NEAR(gold_ccm, ccm, 1e-8); + + const double gold_loss = 4.6386569120323129; + // check loss + const double loss = model.getLoss(); + EXPECT_NEAR(gold_loss, loss, 1e-8); +} + +TEST(CV_mcc_ccm_test, infer) +{ + string path = cvtest::findDataFile("mcc/mcc_ccm_test.jpg"); + Mat img = imread(path, IMREAD_COLOR); + // read gold calibrate img + path = cvtest::findDataFile("mcc/mcc_ccm_test_res.png"); + Mat gold_img = imread(path); + + // read gold chartsRGB + path = cvtest::findDataFile("mcc/mcc_ccm_test.yml"); + FileStorage fs(path, FileStorage::READ); + Mat chartsRGB; + FileNode node = fs["chartsRGB"]; + node >> chartsRGB; + fs.release(); + + // compute CCM + ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth); + model.run(); + + // compute calibrate image + Mat calibratedImage; + cvtColor(img, calibratedImage, COLOR_BGR2RGB); + calibratedImage.convertTo(calibratedImage, CV_64F, 1. / 255.); + calibratedImage = model.infer(calibratedImage); + calibratedImage.convertTo(calibratedImage, CV_8UC3, 255.); + cvtColor(calibratedImage, calibratedImage, COLOR_RGB2BGR); + // check calibrated image + EXPECT_MAT_NEAR(gold_img, calibratedImage, 0.1); +} + } // namespace } // namespace opencv_test diff --git a/modules/ccm/test/test_main.cpp b/modules/ccm/test/test_main.cpp new file mode 100644 index 000000000..556b026ac --- /dev/null +++ b/modules/ccm/test/test_main.cpp @@ -0,0 +1,7 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#include "test_precomp.hpp" + +CV_TEST_MAIN("cv") diff --git a/modules/ccm/test/test_precomp.hpp b/modules/ccm/test/test_precomp.hpp new file mode 100644 index 000000000..b6be71df3 --- /dev/null +++ b/modules/ccm/test/test_precomp.hpp @@ -0,0 +1,17 @@ +// This file is part of OpenCV project. +// It is subject to the license terms in the LICENSE file found in the top-level directory +// of this distribution and at http://opencv.org/license.html. + +#ifndef __OPENCV_TEST_PRECOMP_HPP__ +#define __OPENCV_TEST_PRECOMP_HPP__ + +#include "opencv2/ts.hpp" +#include "opencv2/ts/cuda_test.hpp" +#include "opencv2/ccm.hpp" + +namespace opencv_test +{ +using namespace cv::ccm; +} + +#endif diff --git a/modules/mcc/tutorials/basic_ccm/color_correction_model.markdown b/modules/ccm/tutorials/basic_ccm/color_correction_model.markdown similarity index 96% rename from modules/mcc/tutorials/basic_ccm/color_correction_model.markdown rename to modules/ccm/tutorials/basic_ccm/color_correction_model.markdown index 76b98cd3f..79e102998 100644 --- a/modules/mcc/tutorials/basic_ccm/color_correction_model.markdown +++ b/modules/ccm/tutorials/basic_ccm/color_correction_model.markdown @@ -17,13 +17,13 @@ When building OpenCV, run the following command to build all the contrib modules cmake -D OPENCV_EXTRA_MODULES_PATH=/modules/ ``` -Or only build the mcc module: +Or only build the ccm module: ```make -cmake -D OPENCV_EXTRA_MODULES_PATH=/modules/mcc +cmake -D OPENCV_EXTRA_MODULES_PATH=/modules/ccm ``` -Or make sure you check the mcc module in the GUI version of CMake: cmake-gui. +Or make sure you check the ccm module in the GUI version of CMake: cmake-gui. Source Code of the sample ----------- diff --git a/modules/mcc/tutorials/table_of_content_ccm.markdown b/modules/ccm/tutorials/table_of_content_ccm.markdown similarity index 100% rename from modules/mcc/tutorials/table_of_content_ccm.markdown rename to modules/ccm/tutorials/table_of_content_ccm.markdown diff --git a/modules/mcc/include/opencv2/mcc.hpp b/modules/mcc/include/opencv2/mcc.hpp index e49f3053f..4a264a7ee 100644 --- a/modules/mcc/include/opencv2/mcc.hpp +++ b/modules/mcc/include/opencv2/mcc.hpp @@ -32,15 +32,9 @@ #include "mcc/checker_detector.hpp" #include "mcc/checker_model.hpp" -#include "mcc/ccm.hpp" /** @defgroup mcc Macbeth Chart module @{ - @defgroup color_correction Color Correction Model -@} - - -@addtogroup mcc Introduction ------------ @@ -54,6 +48,7 @@ colors that are present in the image, based on this information we can apply any suitable algorithm to find the actual color of all the objects present in the image. +@} */ #endif diff --git a/modules/mcc/perf/perf_mcc.cpp b/modules/mcc/perf/perf_mcc.cpp index f5e721074..b9a7ec1d0 100644 --- a/modules/mcc/perf/perf_mcc.cpp +++ b/modules/mcc/perf/perf_mcc.cpp @@ -23,29 +23,5 @@ PERF_TEST(CV_mcc_perf, detect) { SANITY_CHECK_NOTHING(); } -PERF_TEST(CV_mcc_perf, infer) { - // read gold chartsRGB - string path = cvtest::findDataFile("cv/mcc/mcc_ccm_test.yml"); - FileStorage fs(path, FileStorage::READ); - Mat chartsRGB; - FileNode node = fs["chartsRGB"]; - node >> chartsRGB; - fs.release(); - - // compute CCM - ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth); - model.run(); - - Mat img(1000, 4000, CV_8UC3); - randu(img, 0, 255); - img.convertTo(img, CV_64F, 1. / 255.); - - TEST_CYCLE() { - model.infer(img); - } - - SANITY_CHECK_NOTHING(); -} - } // namespace } // namespace opencv_test diff --git a/modules/mcc/perf/perf_precomp.hpp b/modules/mcc/perf/perf_precomp.hpp index 5ef546949..447d2c164 100644 --- a/modules/mcc/perf/perf_precomp.hpp +++ b/modules/mcc/perf/perf_precomp.hpp @@ -7,7 +7,6 @@ namespace opencv_test { using namespace cv::mcc; -using namespace cv::ccm; using namespace perf; } diff --git a/modules/mcc/test/test_mcc.cpp b/modules/mcc/test/test_mcc.cpp index 37bd1f11f..1e4a425e6 100644 --- a/modules/mcc/test/test_mcc.cpp +++ b/modules/mcc/test/test_mcc.cpp @@ -117,67 +117,5 @@ TEST(CV_mcc_ccm_test, detect_Macbeth) EXPECT_MAT_NEAR(goldChartsRGB.col(1), chartsRGB.col(1), 0.3); // diff 0.292077 on Ubuntu 20.04 ARM64 } -TEST(CV_mcc_ccm_test, compute_ccm) -{ - // read gold chartsRGB - string path = cvtest::findDataFile("mcc/mcc_ccm_test.yml"); - FileStorage fs(path, FileStorage::READ); - Mat chartsRGB; - FileNode node = fs["chartsRGB"]; - node >> chartsRGB; - - // compute CCM - ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth); - model.run(); - - // read gold CCM - node = fs["ccm"]; - ASSERT_FALSE(node.empty()); - Mat gold_ccm; - node >> gold_ccm; - fs.release(); - - // check CCM - Mat ccm = model.getCCM(); - EXPECT_MAT_NEAR(gold_ccm, ccm, 1e-8); - - const double gold_loss = 4.6386569120323129; - // check loss - const double loss = model.getLoss(); - EXPECT_NEAR(gold_loss, loss, 1e-8); -} - -TEST(CV_mcc_ccm_test, infer) -{ - string path = cvtest::findDataFile("mcc/mcc_ccm_test.jpg"); - Mat img = imread(path, IMREAD_COLOR); - // read gold calibrate img - path = cvtest::findDataFile("mcc/mcc_ccm_test_res.png"); - Mat gold_img = imread(path); - - // read gold chartsRGB - path = cvtest::findDataFile("mcc/mcc_ccm_test.yml"); - FileStorage fs(path, FileStorage::READ); - Mat chartsRGB; - FileNode node = fs["chartsRGB"]; - node >> chartsRGB; - fs.release(); - - // compute CCM - ColorCorrectionModel model(chartsRGB.col(1).clone().reshape(3, chartsRGB.rows/3) / 255., COLORCHECKER_Macbeth); - model.run(); - - // compute calibrate image - Mat calibratedImage; - cvtColor(img, calibratedImage, COLOR_BGR2RGB); - calibratedImage.convertTo(calibratedImage, CV_64F, 1. / 255.); - calibratedImage = model.infer(calibratedImage); - calibratedImage.convertTo(calibratedImage, CV_8UC3, 255.); - cvtColor(calibratedImage, calibratedImage, COLOR_RGB2BGR); - // check calibrated image - EXPECT_MAT_NEAR(gold_img, calibratedImage, 0.1); -} - - } // namespace } // namespace opencv_test diff --git a/modules/mcc/test/test_precomp.hpp b/modules/mcc/test/test_precomp.hpp index c4d81a348..20722f608 100644 --- a/modules/mcc/test/test_precomp.hpp +++ b/modules/mcc/test/test_precomp.hpp @@ -8,12 +8,10 @@ #include "opencv2/ts.hpp" #include "opencv2/ts/cuda_test.hpp" #include "opencv2/mcc.hpp" -#include "opencv2/mcc/ccm.hpp" namespace opencv_test { using namespace cv::mcc; -using namespace cv::ccm; } #endif