diff --git a/modules/mcc/include/opencv2/mcc/checker_model.hpp b/modules/mcc/include/opencv2/mcc/checker_model.hpp index 0768c691e05..5552ea4030b 100644 --- a/modules/mcc/include/opencv2/mcc/checker_model.hpp +++ b/modules/mcc/include/opencv2/mcc/checker_model.hpp @@ -89,6 +89,15 @@ class CV_EXPORTS_W CChecker CV_WRAP virtual TYPECHART getTarget() = 0; CV_WRAP virtual std::vector getBox() = 0; + + /** @brief Computes and returns the coordinates of the central parts of the charts modules. + * + * This method computes transformation matrix from the checkers's coordinates (`cv::mcc::CChecker::getBox()`) + * and find by this the coordinates of the central parts of the charts modules. + * It is used in `cv::mcc::CCheckerDraw::draw()` and in `ChartsRGB` calculation. + */ + CV_WRAP virtual std::vector getColorCharts() = 0; + CV_WRAP virtual Mat getChartsRGB() = 0; CV_WRAP virtual Mat getChartsYCbCr() = 0; CV_WRAP virtual float getCost() = 0; diff --git a/modules/mcc/src/checker_detector.cpp b/modules/mcc/src/checker_detector.cpp index 58c703a6a81..2de276d87fc 100644 --- a/modules/mcc/src/checker_detector.cpp +++ b/modules/mcc/src/checker_detector.cpp @@ -1177,31 +1177,6 @@ void CCheckerDetectorImpl:: x_new.insert(x_new.begin() + idx + 1, (x_new[idx] + x_new[idx + 1]) / 2); } -void CCheckerDetectorImpl:: - transform_points_forward(InputArray T, const std::vector &X, std::vector &Xt) -{ - size_t N = X.size(); - if (N == 0) - return; - - Xt.clear(); - Xt.resize(N); - cv::Matx31f p, xt; - cv::Point2f pt; - - cv::Matx33f _T = T.getMat(); - for (int i = 0; i < (int)N; i++) - { - p(0, 0) = X[i].x; - p(1, 0) = X[i].y; - p(2, 0) = 1; - xt = _T * p; - pt.x = xt(0, 0) / xt(2, 0); - pt.y = xt(1, 0) / xt(2, 0); - Xt[i] = pt; - } -} - void CCheckerDetectorImpl:: transform_points_inverse(InputArray T, const std::vector &X, std::vector &Xt) { diff --git a/modules/mcc/src/checker_detector.hpp b/modules/mcc/src/checker_detector.hpp index 75b1644a51b..4c922b5d1d4 100644 --- a/modules/mcc/src/checker_detector.hpp +++ b/modules/mcc/src/checker_detector.hpp @@ -171,11 +171,6 @@ class CCheckerDetectorImpl : public CCheckerDetector std::vector &x_new, float tol); - void transform_points_forward( - InputArray T, - const std::vector &X, - std::vector &Xt); - void transform_points_inverse( InputArray T, const std::vector &X, diff --git a/modules/mcc/src/checker_model.cpp b/modules/mcc/src/checker_model.cpp index 2062e7705e5..310ed8baf96 100644 --- a/modules/mcc/src/checker_model.cpp +++ b/modules/mcc/src/checker_model.cpp @@ -411,6 +411,39 @@ std::vector CCheckerImpl::getBox() { return box; } +std::vector CCheckerImpl::getColorCharts() +{ + // color chart classic model + CChartModel cccm(getTarget()); + Mat lab; + size_t N; + std::vector fbox = cccm.box; + std::vector cellchart = cccm.cellchart; + std::vector charts(cellchart.size()); + + // tranformation + Matx33f ccT = getPerspectiveTransform(fbox, getBox()); + + std::vector bch(4), bcht(4); + N = cellchart.size() / 4; + for (size_t i = 0, k; i < N; i++) + { + k = 4 * i; + for (size_t j = 0ull; j < 4ull; j++) + bch[j] = cellchart[k + j]; + + polyanticlockwise(bch); + transform_points_forward(ccT, bch, bcht); + + Point2f c(0, 0); + for (size_t j = 0; j < 4; j++) + c += bcht[j]; + c /= 4; + for (size_t j = 0ull; j < 4ull; j++) + charts[k+j] = ((bcht[j] - c) * 0.50) + c; + } + return charts; +} Mat CCheckerImpl::getChartsRGB() { return chartsRGB; @@ -435,70 +468,40 @@ Ptr CCheckerDraw::create(Ptr pChecker, cv::Scalar color return makePtr(pChecker, color, thickness); } -void CCheckerDrawImpl:: - draw(InputOutputArray img) +void CCheckerDrawImpl::draw(InputOutputArray img) { - - // color chart classic model - CChartModel cccm(m_pChecker->getTarget()); - cv::Mat lab; - size_t N; - std::vector fbox = cccm.box; - std::vector cellchart = cccm.cellchart; - - // tranformation - cv::Matx33f ccT = cv::getPerspectiveTransform(fbox, m_pChecker->getBox()); - - std::vector bch(4), bcht(4); - N = cellchart.size() / 4; + std::vector charts = m_pChecker->getColorCharts(); + size_t N = charts.size() / 4; for (size_t i = 0, k; i < N; i++) { k = 4 * i; - bch[0] = cellchart[k + 0]; - bch[1] = cellchart[k + 1]; - bch[2] = cellchart[k + 2]; - bch[3] = cellchart[k + 3]; - - polyanticlockwise(bch); - transform_points_forward(ccT, bch, bcht); - - cv::Point2f c(0, 0); for (size_t j = 0; j < 4; j++) - c += bcht[j]; - c /= 4; - for (size_t j = 0; j < 4; j++) - bcht[j] = ((bcht[j] - c) * 0.50) + c; - - cv::line(img, bcht[0], bcht[1], m_color, m_thickness, LINE_AA); - cv::line(img, bcht[1], bcht[2], m_color, m_thickness, LINE_AA); - cv::line(img, bcht[2], bcht[3], m_color, m_thickness, LINE_AA); - cv::line(img, bcht[3], bcht[0], m_color, m_thickness, LINE_AA); + cv::line(img, charts[k+j], charts[k+((j + 1) % 4)], m_color, m_thickness, LINE_AA); } } -void CCheckerDrawImpl:: - transform_points_forward(InputArray T, const std::vector &X, std::vector &Xt) +void transform_points_forward(const Matx33f& T, const std::vector &X, std::vector &Xt) { - - cv::Matx33f _T = T.getMat(); size_t N = X.size(); - Xt.clear(); - Xt.resize(N); + if (Xt.size() != N) + Xt.resize(N); + std::fill(Xt.begin(), Xt.end(), Point2f(0.f, 0.f)); if (N == 0) return; - cv::Matx31f p, xt; - cv::Point2f pt; + Matx31f p, xt; + Point2f pt; for (size_t i = 0; i < N; i++) { p(0, 0) = X[i].x; p(1, 0) = X[i].y; p(2, 0) = 1; - xt = _T * p; + xt = T * p; pt.x = xt(0, 0) / xt(2, 0); pt.y = xt(1, 0) / xt(2, 0); Xt[i] = pt; } } + } // namespace mcc } // namespace cv diff --git a/modules/mcc/src/checker_model.hpp b/modules/mcc/src/checker_model.hpp index 31b85a5a144..4f116a8bdf5 100644 --- a/modules/mcc/src/checker_model.hpp +++ b/modules/mcc/src/checker_model.hpp @@ -137,6 +137,7 @@ class CCheckerImpl : public CChecker TYPECHART getTarget() CV_OVERRIDE; std::vector getBox() CV_OVERRIDE; + std::vector getColorCharts() CV_OVERRIDE; Mat getChartsRGB() CV_OVERRIDE; Mat getChartsYCbCr() CV_OVERRIDE; float getCost() CV_OVERRIDE; @@ -173,16 +174,11 @@ class CCheckerDrawImpl : public CCheckerDraw Ptr m_pChecker; cv::Scalar m_color; int m_thickness; - -private: - /** \brief transformation perspetive*/ - void transform_points_forward( - InputArray T, - const std::vector &X, - std::vector &Xt); }; // @} +void transform_points_forward(const Matx33f& T, const std::vector &X, std::vector &Xt); + } // namespace mcc } // namespace cv