@@ -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+ }
414447Mat 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
0 commit comments