pull/3895/merge
Gursimar Singh 3 weeks ago committed by GitHub
commit f1f5d8e224
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      modules/ccm/CMakeLists.txt
  2. 7
      modules/ccm/include/opencv2/ccm.hpp
  3. 41
      modules/ccm/perf/perf_ccm.cpp
  4. 3
      modules/ccm/perf/perf_main.cpp
  5. 13
      modules/ccm/perf/perf_precomp.hpp
  6. 4
      modules/ccm/samples/color_correction_model.cpp
  7. 2
      modules/ccm/src/ccm.cpp
  8. 0
      modules/ccm/src/color.cpp
  9. 6
      modules/ccm/src/color.hpp
  10. 0
      modules/ccm/src/colorspace.cpp
  11. 6
      modules/ccm/src/colorspace.hpp
  12. 0
      modules/ccm/src/distance.cpp
  13. 6
      modules/ccm/src/distance.hpp
  14. 0
      modules/ccm/src/io.cpp
  15. 4
      modules/ccm/src/io.hpp
  16. 0
      modules/ccm/src/linearize.cpp
  17. 6
      modules/ccm/src/linearize.hpp
  18. 0
      modules/ccm/src/operations.cpp
  19. 4
      modules/ccm/src/operations.hpp
  20. 44
      modules/ccm/src/precomp.hpp
  21. 0
      modules/ccm/src/utils.cpp
  22. 4
      modules/ccm/src/utils.hpp
  23. 61
      modules/ccm/test/test_ccm.cpp
  24. 7
      modules/ccm/test/test_main.cpp
  25. 17
      modules/ccm/test/test_precomp.hpp
  26. 6
      modules/ccm/tutorials/basic_ccm/color_correction_model.markdown
  27. 0
      modules/ccm/tutorials/table_of_content_ccm.markdown
  28. 7
      modules/mcc/include/opencv2/mcc.hpp
  29. 24
      modules/mcc/perf/perf_mcc.cpp
  30. 1
      modules/mcc/perf/perf_precomp.hpp
  31. 62
      modules/mcc/test/test_mcc.cpp
  32. 2
      modules/mcc/test/test_precomp.hpp

@ -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)

@ -25,8 +25,8 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#ifndef __OPENCV_MCC_CCM_HPP__
#define __OPENCV_MCC_CCM_HPP__
#ifndef __OPENCV_CCM_HPP__
#define __OPENCV_CCM_HPP__
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
@ -35,7 +35,8 @@ namespace cv
{
namespace ccm
{
/** @addtogroup color_correction
/** @defgroup ccm Color Correction module
@{
Introduction

@ -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

@ -0,0 +1,3 @@
#include "perf_precomp.hpp"
CV_PERF_TEST_MAIN(ccm)

@ -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

@ -4,13 +4,13 @@
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/mcc.hpp>
#include <opencv2/ccm.hpp>
#include <iostream>
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 "<<ccm<<std::endl;

@ -25,7 +25,7 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#include "opencv2/mcc/ccm.hpp"
#include "opencv2/ccm.hpp"
#include "linearize.hpp"
namespace cv {
namespace ccm {

@ -25,12 +25,12 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#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 {

@ -25,12 +25,12 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#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 {

@ -25,11 +25,11 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#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 {

@ -25,8 +25,8 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#ifndef __OPENCV_MCC_IO_HPP__
#define __OPENCV_MCC_IO_HPP__
#ifndef __OPENCV_CCM_IO_HPP__
#define __OPENCV_CCM_IO_HPP__
#include <opencv2/core.hpp>
#include <map>

@ -25,13 +25,13 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#ifndef __OPENCV_MCC_LINEARIZE_HPP__
#define __OPENCV_MCC_LINEARIZE_HPP__
#ifndef __OPENCV_CCM_LINEARIZE_HPP__
#define __OPENCV_CCM_LINEARIZE_HPP__
#include <opencv2/core.hpp>
#include <map>
#include "color.hpp"
#include "opencv2/mcc/ccm.hpp"
#include "opencv2/ccm.hpp"
namespace cv {
namespace ccm {

@ -25,8 +25,8 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#ifndef __OPENCV_MCC_OPERATIONS_HPP__
#define __OPENCV_MCC_OPERATIONS_HPP__
#ifndef __OPENCV_CCM_OPERATIONS_HPP__
#define __OPENCV_CCM_OPERATIONS_HPP__
#include "utils.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 <limits>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/3d.hpp>
#include <opencv2/dnn.hpp>
#include <vector>
#include <string>
#include "opencv2/ccm.hpp"
#endif //_MCC_PRECOMP_HPP

@ -25,8 +25,8 @@
// Jinheng Zhang <zhangjinheng1@huawei.com>
// Chenqi Shan <shanchenqi@huawei.com>
#ifndef __OPENCV_MCC_UTILS_HPP__
#define __OPENCV_MCC_UTILS_HPP__
#ifndef __OPENCV_CCM_UTILS_HPP__
#define __OPENCV_CCM_UTILS_HPP__
#include <opencv2/core.hpp>

@ -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

@ -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")

@ -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

@ -17,13 +17,13 @@ When building OpenCV, run the following command to build all the contrib modules
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/
```
Or only build the mcc module:
Or only build the ccm module:
```make
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules/mcc
cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/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
-----------

@ -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

@ -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

@ -7,7 +7,6 @@
namespace opencv_test
{
using namespace cv::mcc;
using namespace cv::ccm;
using namespace perf;
}

@ -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

@ -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

Loading…
Cancel
Save