Skip to content

Commit c0aa450

Browse files
added getComputedCharts()
1 parent 97137ec commit c0aa450

File tree

3 files changed

+70
-64
lines changed

3 files changed

+70
-64
lines changed

modules/mcc/include/opencv2/mcc/checker_model.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ class CV_EXPORTS_W CChecker
8989

9090
CV_WRAP virtual TYPECHART getTarget() = 0;
9191
CV_WRAP virtual std::vector<Point2f> getBox() = 0;
92+
93+
/** @brief Computes and returns the coordinates of the central parts of the charts modules.
94+
*
95+
* This method computes transformation matrix from the checkers's coordinates (`cv::mcc::CChecker::getBox()`)
96+
* and find by this the coordinates of the central parts of the charts modules.
97+
* It is used in `cv::mcc::CCheckerDraw::draw()` and in `ChartsRGB` calculation.
98+
*/
99+
CV_WRAP virtual std::vector<Point2f> getComputedCharts() = 0;
100+
92101
CV_WRAP virtual Mat getChartsRGB() = 0;
93102
CV_WRAP virtual Mat getChartsYCbCr() = 0;
94103
CV_WRAP virtual float getCost() = 0;

modules/mcc/src/checker_model.cpp

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,29 @@ void CChartModel::
370370
}
371371
}
372372

373+
static inline
374+
void transform_points_forward(const cv::Matx33f& T, const std::vector<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
375+
{
376+
size_t N = X.size();
377+
Xt.clear();
378+
Xt.resize(N);
379+
if (N == 0)
380+
return;
381+
382+
cv::Matx31f p, xt;
383+
cv::Point2f pt;
384+
for (size_t i = 0; i < N; i++)
385+
{
386+
p(0, 0) = X[i].x;
387+
p(1, 0) = X[i].y;
388+
p(2, 0) = 1;
389+
xt = T * p;
390+
pt.x = xt(0, 0) / xt(2, 0);
391+
pt.y = xt(1, 0) / xt(2, 0);
392+
Xt[i] = pt;
393+
}
394+
}
395+
373396
//////////////////////////////////////////////////////////////////////////////////////////////
374397
// // CChecker
375398

@@ -411,6 +434,39 @@ std::vector<Point2f> CCheckerImpl::getBox()
411434
{
412435
return box;
413436
}
437+
std::vector<Point2f> CCheckerImpl::getComputedCharts()
438+
{
439+
// color chart classic model
440+
CChartModel cccm(getTarget());
441+
cv::Mat lab;
442+
size_t N;
443+
std::vector<cv::Point2f> fbox = cccm.box;
444+
std::vector<cv::Point2f> cellchart = cccm.cellchart;
445+
std::vector<Point2f> charts(cellchart.size());
446+
447+
// tranformation
448+
cv::Matx33f ccT = cv::getPerspectiveTransform(fbox, getBox());
449+
450+
std::vector<cv::Point2f> bch(4), bcht(4);
451+
N = cellchart.size() / 4;
452+
for (size_t i = 0, k; i < N; i++)
453+
{
454+
k = 4 * i;
455+
for (size_t j = 0ull; j < 4ull; j++)
456+
bch[j] = cellchart[k + j];
457+
458+
polyanticlockwise(bch);
459+
transform_points_forward(ccT, bch, bcht);
460+
461+
cv::Point2f c(0, 0);
462+
for (size_t j = 0; j < 4; j++)
463+
c += bcht[j];
464+
c /= 4;
465+
for (size_t j = 0ull; j < 4ull; j++)
466+
charts[k+j] = ((bcht[j] - c) * 0.50) + c;
467+
}
468+
return charts;
469+
}
414470
Mat CCheckerImpl::getChartsRGB()
415471
{
416472
return chartsRGB;
@@ -435,70 +491,17 @@ Ptr<CCheckerDraw> CCheckerDraw::create(Ptr<CChecker> pChecker, cv::Scalar color
435491
return makePtr<CCheckerDrawImpl>(pChecker, color, thickness);
436492
}
437493

438-
void CCheckerDrawImpl::
439-
draw(InputOutputArray img)
494+
void CCheckerDrawImpl::draw(InputOutputArray img)
440495
{
441-
442-
// color chart classic model
443-
CChartModel cccm(m_pChecker->getTarget());
444-
cv::Mat lab;
445-
size_t N;
446-
std::vector<cv::Point2f> fbox = cccm.box;
447-
std::vector<cv::Point2f> cellchart = cccm.cellchart;
448-
449-
// tranformation
450-
cv::Matx33f ccT = cv::getPerspectiveTransform(fbox, m_pChecker->getBox());
451-
452-
std::vector<cv::Point2f> bch(4), bcht(4);
453-
N = cellchart.size() / 4;
496+
std::vector<Point2f> charts = m_pChecker->getComputedCharts();
497+
size_t N = charts.size() / 4;
454498
for (size_t i = 0, k; i < N; i++)
455499
{
456500
k = 4 * i;
457-
bch[0] = cellchart[k + 0];
458-
bch[1] = cellchart[k + 1];
459-
bch[2] = cellchart[k + 2];
460-
bch[3] = cellchart[k + 3];
461-
462-
polyanticlockwise(bch);
463-
transform_points_forward(ccT, bch, bcht);
464-
465-
cv::Point2f c(0, 0);
466-
for (size_t j = 0; j < 4; j++)
467-
c += bcht[j];
468-
c /= 4;
469501
for (size_t j = 0; j < 4; j++)
470-
bcht[j] = ((bcht[j] - c) * 0.50) + c;
471-
472-
cv::line(img, bcht[0], bcht[1], m_color, m_thickness, LINE_AA);
473-
cv::line(img, bcht[1], bcht[2], m_color, m_thickness, LINE_AA);
474-
cv::line(img, bcht[2], bcht[3], m_color, m_thickness, LINE_AA);
475-
cv::line(img, bcht[3], bcht[0], m_color, m_thickness, LINE_AA);
502+
cv::line(img, charts[k+j], charts[k+((j + 1) % 4)], m_color, m_thickness, LINE_AA);
476503
}
477504
}
478505

479-
void CCheckerDrawImpl::
480-
transform_points_forward(InputArray T, const std::vector<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
481-
{
482-
483-
cv::Matx33f _T = T.getMat();
484-
size_t N = X.size();
485-
Xt.clear();
486-
Xt.resize(N);
487-
if (N == 0)
488-
return;
489-
490-
cv::Matx31f p, xt;
491-
cv::Point2f pt;
492-
for (size_t i = 0; i < N; i++)
493-
{
494-
p(0, 0) = X[i].x;
495-
p(1, 0) = X[i].y;
496-
p(2, 0) = 1;
497-
xt = _T * p;
498-
pt.x = xt(0, 0) / xt(2, 0);
499-
pt.y = xt(1, 0) / xt(2, 0);
500-
Xt[i] = pt;
501-
}
502-
}
503506
} // namespace mcc
504507
} // namespace cv

modules/mcc/src/checker_model.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class CCheckerImpl : public CChecker
137137

138138
TYPECHART getTarget() CV_OVERRIDE;
139139
std::vector<Point2f> getBox() CV_OVERRIDE;
140+
std::vector<Point2f> getComputedCharts() CV_OVERRIDE;
140141
Mat getChartsRGB() CV_OVERRIDE;
141142
Mat getChartsYCbCr() CV_OVERRIDE;
142143
float getCost() CV_OVERRIDE;
@@ -173,13 +174,6 @@ class CCheckerDrawImpl : public CCheckerDraw
173174
Ptr<CChecker> m_pChecker;
174175
cv::Scalar m_color;
175176
int m_thickness;
176-
177-
private:
178-
/** \brief transformation perspetive*/
179-
void transform_points_forward(
180-
InputArray T,
181-
const std::vector<cv::Point2f> &X,
182-
std::vector<cv::Point2f> &Xt);
183177
};
184178
// @}
185179

0 commit comments

Comments
 (0)