Skip to content

Commit 7f445c2

Browse files
added getComputedColorCharts()
1 parent 97137ec commit 7f445c2

File tree

5 files changed

+59
-79
lines changed

5 files changed

+59
-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> getComputedColorCharts() = 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: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ void CChartModel::
370370
}
371371
}
372372

373+
374+
373375
//////////////////////////////////////////////////////////////////////////////////////////////
374376
// // CChecker
375377

@@ -411,6 +413,39 @@ std::vector<Point2f> CCheckerImpl::getBox()
411413
{
412414
return box;
413415
}
416+
std::vector<Point2f> CCheckerImpl::getComputedColorCharts()
417+
{
418+
// color chart classic model
419+
CChartModel cccm(getTarget());
420+
Mat lab;
421+
size_t N;
422+
std::vector<Point2f> fbox = cccm.box;
423+
std::vector<Point2f> cellchart = cccm.cellchart;
424+
std::vector<Point2f> charts(cellchart.size());
425+
426+
// tranformation
427+
Matx33f ccT = getPerspectiveTransform(fbox, getBox());
428+
429+
std::vector<Point2f> bch(4), bcht(4);
430+
N = cellchart.size() / 4;
431+
for (size_t i = 0, k; i < N; i++)
432+
{
433+
k = 4 * i;
434+
for (size_t j = 0ull; j < 4ull; j++)
435+
bch[j] = cellchart[k + j];
436+
437+
polyanticlockwise(bch);
438+
transform_points_forward(ccT, bch, bcht);
439+
440+
Point2f c(0, 0);
441+
for (size_t j = 0; j < 4; j++)
442+
c += bcht[j];
443+
c /= 4;
444+
for (size_t j = 0ull; j < 4ull; j++)
445+
charts[k+j] = ((bcht[j] - c) * 0.50) + c;
446+
}
447+
return charts;
448+
}
414449
Mat CCheckerImpl::getChartsRGB()
415450
{
416451
return chartsRGB;
@@ -435,70 +470,40 @@ Ptr<CCheckerDraw> CCheckerDraw::create(Ptr<CChecker> pChecker, cv::Scalar color
435470
return makePtr<CCheckerDrawImpl>(pChecker, color, thickness);
436471
}
437472

438-
void CCheckerDrawImpl::
439-
draw(InputOutputArray img)
473+
void CCheckerDrawImpl::draw(InputOutputArray img)
440474
{
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;
475+
std::vector<Point2f> charts = m_pChecker->getComputedColorCharts();
476+
size_t N = charts.size() / 4;
454477
for (size_t i = 0, k; i < N; i++)
455478
{
456479
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);
466480
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);
481+
cv::line(img, charts[k+j], charts[k+((j + 1) % 4)], m_color, m_thickness, LINE_AA);
476482
}
477483
}
478484

479-
void CCheckerDrawImpl::
480-
transform_points_forward(InputArray T, const std::vector<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
485+
void transform_points_forward(const Matx33f& T, const std::vector<Point2f> &X, std::vector<Point2f> &Xt)
481486
{
482-
483-
cv::Matx33f _T = T.getMat();
484487
size_t N = X.size();
485-
Xt.clear();
486-
Xt.resize(N);
488+
if (Xt.size() != N)
489+
Xt.resize(N);
490+
std::fill(Xt.begin(), Xt.end(), Point2f(0.f, 0.f));
487491
if (N == 0)
488492
return;
489493

490-
cv::Matx31f p, xt;
491-
cv::Point2f pt;
494+
Matx31f p, xt;
495+
Point2f pt;
492496
for (size_t i = 0; i < N; i++)
493497
{
494498
p(0, 0) = X[i].x;
495499
p(1, 0) = X[i].y;
496500
p(2, 0) = 1;
497-
xt = _T * p;
501+
xt = T * p;
498502
pt.x = xt(0, 0) / xt(2, 0);
499503
pt.y = xt(1, 0) / xt(2, 0);
500504
Xt[i] = pt;
501505
}
502506
}
507+
503508
} // namespace mcc
504509
} // 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> getComputedColorCharts() 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)