Ask Your Question

Revision history [back]

The application seems to be crashing because of the infinite loop. As you are looking for new match by Core.minMaxLoc(result) in same result matrix its always returning the first occurrence.

So whenever you found a match you need to remove that match from the result and look for the next match. I removed the match by using filled rectangleCV_FILLED or (-1) in result matrix.

while(true)
{
    mmr = Core.minMaxLoc(result);
    matchLoc = mmr.maxLoc;
    if(mmr.maxVal >=0.9)
    {
        Core.rectangle(img, matchLoc, 
            new Point(matchLoc.x + templ.cols(),matchLoc.y + templ.rows()), 
            new    Scalar(0,255,0));
        Core.rectangle(result, matchLoc, 
            new Point(matchLoc.x + templ.cols(),matchLoc.y + templ.rows()), 
            new    Scalar(0,255,0),-1);
        //break;
    }
    else
    {
        break; //No more results within tolerance, break search
    }
}