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