Match Template in predefined areas
I am trying to optimize my code, since now it works very clunky. For now i use this:
while (true)
{
double minval, maxval, thresh = 0.8;
Point minloc, maxloc;
matchTemplate(gref, gtpl, res, CV_TM_CCOEFF_NORMED);
threshold(res, res, 0.85, 1., CV_THRESH_TOZERO);
minMaxLoc(res, &minval, &maxval, &minloc, &maxloc);
if (maxval <= thresh)
{
resize(gtpl, gtpl, Size(gtpl.cols-1, gtpl.rows-1));
}
else
{
break;
}
}
while (true)
{
double minval, maxval, thresh = 0.8;
Point minloc, maxloc;
minMaxLoc(res, &minval, &maxval, &minloc, &maxloc);
if (maxval >= thresh)
{
floodFill(res, maxloc, Scalar(0), 0, Scalar(.1), Scalar(1.));
if(maxloc.x < 600 && maxloc.y > 800)
{
x = maxloc.x + gtpl.rows;
y = maxloc.y;
}
else if( maxloc.x < 600 && maxloc.y < 600)
{
x = maxloc.x + gtpl.cols ;
y = maxloc.y + gtpl.cols;
}
else
{
x = maxloc.x ;
y = maxloc.y + gtpl.rows;
}
circle(ref, Point(x, y), 5, CV_RGB(0, 0, 255));
}
else
{
break;
}
}
For now i define areas of searching in pixels, but if image will be diffrenet, resolution may be too and everything will mess up. Maybe someone can advice me in using % or something similar?
C:\fakepath\table.png