Skip to content

Commit 45f560b

Browse files
added getColorCharts()
1 parent 6b5142f commit 45f560b

File tree

5 files changed

+57
-79
lines changed

5 files changed

+57
-79
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> getColorCharts() = 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_detector.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,31 +1176,6 @@ void CCheckerDetectorImpl::
11761176
x_new.insert(x_new.begin() + idx + 1, (x_new[idx] + x_new[idx + 1]) / 2);
11771177
}
11781178

1179-
void CCheckerDetectorImpl::
1180-
transform_points_forward(InputArray T, const std::vector<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
1181-
{
1182-
size_t N = X.size();
1183-
if (N == 0)
1184-
return;
1185-
1186-
Xt.clear();
1187-
Xt.resize(N);
1188-
cv::Matx31f p, xt;
1189-
cv::Point2f pt;
1190-
1191-
cv::Matx33f _T = T.getMat();
1192-
for (int i = 0; i < (int)N; i++)
1193-
{
1194-
p(0, 0) = X[i].x;
1195-
p(1, 0) = X[i].y;
1196-
p(2, 0) = 1;
1197-
xt = _T * p;
1198-
pt.x = xt(0, 0) / xt(2, 0);
1199-
pt.y = xt(1, 0) / xt(2, 0);
1200-
Xt[i] = pt;
1201-
}
1202-
}
1203-
12041179
void CCheckerDetectorImpl::
12051180
transform_points_inverse(InputArray T, const std::vector<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
12061181
{

modules/mcc/src/checker_detector.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,6 @@ class CCheckerDetectorImpl : public CCheckerDetector
171171
std::vector<float> &x_new,
172172
float tol);
173173

174-
void transform_points_forward(
175-
InputArray T,
176-
const std::vector<cv::Point2f> &X,
177-
std::vector<cv::Point2f> &Xt);
178-
179174
void transform_points_inverse(
180175
InputArray T,
181176
const std::vector<cv::Point2f> &X,

modules/mcc/src/checker_model.cpp

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,39 @@ std::vector<Point2f> CCheckerImpl::getBox()
411411
{
412412
return box;
413413
}
414+
std::vector<Point2f> CCheckerImpl::getColorCharts()
415+
{
416+
// color chart classic model
417+
CChartModel cccm(getTarget());
418+
Mat lab;
419+
size_t N;
420+
std::vector<Point2f> fbox = cccm.box;
421+
std::vector<Point2f> cellchart = cccm.cellchart;
422+
std::vector<Point2f> charts(cellchart.size());
423+
424+
// tranformation
425+
Matx33f ccT = getPerspectiveTransform(fbox, getBox());
426+
427+
std::vector<Point2f> bch(4), bcht(4);
428+
N = cellchart.size() / 4;
429+
for (size_t i = 0, k; i < N; i++)
430+
{
431+
k = 4 * i;
432+
for (size_t j = 0ull; j < 4ull; j++)
433+
bch[j] = cellchart[k + j];
434+
435+
polyanticlockwise(bch);
436+
transform_points_forward(ccT, bch, bcht);
437+
438+
Point2f c(0, 0);
439+
for (size_t j = 0; j < 4; j++)
440+
c += bcht[j];
441+
c /= 4;
442+
for (size_t j = 0ull; j < 4ull; j++)
443+
charts[k+j] = ((bcht[j] - c) * 0.50) + c;
444+
}
445+
return charts;
446+
}
414447
Mat CCheckerImpl::getChartsRGB()
415448
{
416449
return chartsRGB;
@@ -435,70 +468,40 @@ Ptr<CCheckerDraw> CCheckerDraw::create(Ptr<CChecker> pChecker, cv::Scalar color
435468
return makePtr<CCheckerDrawImpl>(pChecker, color, thickness);
436469
}
437470

438-
void CCheckerDrawImpl::
439-
draw(InputOutputArray img)
471+
void CCheckerDrawImpl::draw(InputOutputArray img)
440472
{
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;
473+
std::vector<Point2f> charts = m_pChecker->getColorCharts();
474+
size_t N = charts.size() / 4;
454475
for (size_t i = 0, k; i < N; i++)
455476
{
456477
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);
466478
for (size_t j = 0; j < 4; j++)
467-
c += bcht[j];
468-
c /= 4;
469-
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);
479+
cv::line(img, charts[k+j], charts[k+((j + 1) % 4)], m_color, m_thickness, LINE_AA);
476480
}
477481
}
478482

479-
void CCheckerDrawImpl::
480-
transform_points_forward(InputArray T, const std::vector<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
483+
void transform_points_forward(const Matx33f& T, const std::vector<Point2f> &X, std::vector<Point2f> &Xt)
481484
{
482-
483-
cv::Matx33f _T = T.getMat();
484485
size_t N = X.size();
485-
Xt.clear();
486-
Xt.resize(N);
486+
if (Xt.size() != N)
487+
Xt.resize(N);
488+
std::fill(Xt.begin(), Xt.end(), Point2f(0.f, 0.f));
487489
if (N == 0)
488490
return;
489491

490-
cv::Matx31f p, xt;
491-
cv::Point2f pt;
492+
Matx31f p, xt;
493+
Point2f pt;
492494
for (size_t i = 0; i < N; i++)
493495
{
494496
p(0, 0) = X[i].x;
495497
p(1, 0) = X[i].y;
496498
p(2, 0) = 1;
497-
xt = _T * p;
499+
xt = T * p;
498500
pt.x = xt(0, 0) / xt(2, 0);
499501
pt.y = xt(1, 0) / xt(2, 0);
500502
Xt[i] = pt;
501503
}
502504
}
505+
503506
} // namespace mcc
504507
} // namespace cv

modules/mcc/src/checker_model.hpp

Lines changed: 3 additions & 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> getColorCharts() CV_OVERRIDE;
140141
Mat getChartsRGB() CV_OVERRIDE;
141142
Mat getChartsYCbCr() CV_OVERRIDE;
142143
float getCost() CV_OVERRIDE;
@@ -173,16 +174,11 @@ 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

180+
void transform_points_forward(const Matx33f& T, const std::vector<Point2f> &X, std::vector<Point2f> &Xt);
181+
186182
} // namespace mcc
187183
} // namespace cv
188184

0 commit comments

Comments
 (0)