added getColorCharts()

pull/3645/head
Alex 1 year ago
parent 6b5142ff65
commit 45f560b027
  1. 9
      modules/mcc/include/opencv2/mcc/checker_model.hpp
  2. 25
      modules/mcc/src/checker_detector.cpp
  3. 5
      modules/mcc/src/checker_detector.hpp
  4. 87
      modules/mcc/src/checker_model.cpp
  5. 10
      modules/mcc/src/checker_model.hpp

@ -89,6 +89,15 @@ public:
CV_WRAP virtual TYPECHART getTarget() = 0;
CV_WRAP virtual std::vector<Point2f> 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<Point2f> getColorCharts() = 0;
CV_WRAP virtual Mat getChartsRGB() = 0;
CV_WRAP virtual Mat getChartsYCbCr() = 0;
CV_WRAP virtual float getCost() = 0;

@ -1176,31 +1176,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<cv::Point2f> &X, std::vector<cv::Point2f> &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<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
{

@ -171,11 +171,6 @@ private: // methods aux
std::vector<float> &x_new,
float tol);
void transform_points_forward(
InputArray T,
const std::vector<cv::Point2f> &X,
std::vector<cv::Point2f> &Xt);
void transform_points_inverse(
InputArray T,
const std::vector<cv::Point2f> &X,

@ -411,6 +411,39 @@ std::vector<Point2f> CCheckerImpl::getBox()
{
return box;
}
std::vector<Point2f> CCheckerImpl::getColorCharts()
{
// color chart classic model
CChartModel cccm(getTarget());
Mat lab;
size_t N;
std::vector<Point2f> fbox = cccm.box;
std::vector<Point2f> cellchart = cccm.cellchart;
std::vector<Point2f> charts(cellchart.size());
// tranformation
Matx33f ccT = getPerspectiveTransform(fbox, getBox());
std::vector<Point2f> 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> CCheckerDraw::create(Ptr<CChecker> pChecker, cv::Scalar color
return makePtr<CCheckerDrawImpl>(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<cv::Point2f> fbox = cccm.box;
std::vector<cv::Point2f> cellchart = cccm.cellchart;
// tranformation
cv::Matx33f ccT = cv::getPerspectiveTransform(fbox, m_pChecker->getBox());
std::vector<cv::Point2f> bch(4), bcht(4);
N = cellchart.size() / 4;
std::vector<Point2f> 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<cv::Point2f> &X, std::vector<cv::Point2f> &Xt)
void transform_points_forward(const Matx33f& T, const std::vector<Point2f> &X, std::vector<Point2f> &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

@ -137,6 +137,7 @@ public:
TYPECHART getTarget() CV_OVERRIDE;
std::vector<Point2f> getBox() CV_OVERRIDE;
std::vector<Point2f> getColorCharts() CV_OVERRIDE;
Mat getChartsRGB() CV_OVERRIDE;
Mat getChartsYCbCr() CV_OVERRIDE;
float getCost() CV_OVERRIDE;
@ -173,16 +174,11 @@ private:
Ptr<CChecker> m_pChecker;
cv::Scalar m_color;
int m_thickness;
private:
/** \brief transformation perspetive*/
void transform_points_forward(
InputArray T,
const std::vector<cv::Point2f> &X,
std::vector<cv::Point2f> &Xt);
};
// @}
void transform_points_forward(const Matx33f& T, const std::vector<Point2f> &X, std::vector<Point2f> &Xt);
} // namespace mcc
} // namespace cv

Loading…
Cancel
Save