MCPcopy Create free account
hub / github.com/DennisLiu1993/Fastest_Image_Pattern_Matching / LearnPattern

Method LearnPattern

MatchTool/MatchToolDlg.cpp:453–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

451 line (matDraw, ptC - Point (0, iLength), ptC + Point (0, iLength), color, iThickness);
452}
453void CMatchToolDlg::LearnPattern ()
454{
455 UpdateData (1);;
456 m_TemplData.clear ();
457
458 int iTopLayer = GetTopLayer (&m_matDst, (int)sqrt ((double)m_iMinReduceArea));
459 buildPyramid (m_matDst, m_TemplData.vecPyramid, iTopLayer);
460 s_TemplData* templData = &m_TemplData;
461 templData->iBorderColor = mean (m_matDst).val[0] < 128 ? 255 : 0;
462 int iSize = templData->vecPyramid.size ();
463 templData->resize (iSize);
464
465 for (int i = 0; i < iSize; i++)
466 {
467 double invArea = 1. / ((double)templData->vecPyramid[i].rows * templData->vecPyramid[i].cols);
468 Scalar templMean, templSdv;
469 double templNorm = 0, templSum2 = 0;
470
471 meanStdDev (templData->vecPyramid[i], templMean, templSdv);
472 templNorm = templSdv[0] * templSdv[0] + templSdv[1] * templSdv[1] + templSdv[2] * templSdv[2] + templSdv[3] * templSdv[3];
473
474 if (templNorm < DBL_EPSILON)
475 {
476 templData->vecResultEqual1[i] = TRUE;
477 }
478 templSum2 = templNorm + templMean[0] * templMean[0] + templMean[1] * templMean[1] + templMean[2] * templMean[2] + templMean[3] * templMean[3];
479
480
481 templSum2 /= invArea;
482 templNorm = std::sqrt (templNorm);
483 templNorm /= std::sqrt (invArea); // care of accuracy here
484
485
486 templData->vecInvArea[i] = invArea;
487 templData->vecTemplMean[i] = templMean;
488 templData->vecTemplNorm[i] = templNorm;
489 }
490 templData->bIsPatternLearned = TRUE;
491}
492
493int CMatchToolDlg::GetTopLayer (Mat* matTempl, int iMinDstLength)
494{

Callers

nothing calls this directly

Calls 2

clearMethod · 0.80
resizeMethod · 0.80

Tested by

no test coverage detected