private static void drawRectangles ( Graphics2D g2 , GrayF32 image , GrayF32 template , GrayF32 mask , int expectedMatches ) { List < Match > found = findMatches ( image , template , mask , expectedMatches ) ; int r = 2 ; int w = template . width + 2 * r ; int h = template . height + 2 * r ; for ( Match m : found ) { System . out . println ( "Match " + m . x + " " + m . y + " score " + m . score ) ; // this demonstrates how to filter out false positives // the meaning of score will depend on the template technique // if( m.score < -1000 ) // This line is commented out for demonstration purposes // continue; // the return point is the template's top left corner int x0 = m . x - r ; int y0 = m . y - r ; int x1 = x0 + w ; int y1 = y0 + h ; g2 . drawLine ( x0 , y0 , x1 , y0 ) ; g2 . drawLine ( x1 , y0 , x1 , y1 ) ; g2 . drawLine ( x1 , y1 , x0 , y1 ) ; g2 . drawLine ( x0 , y1 , x0 , y0 ) ; } }
Helper function will is finds matches and displays the results as colored rectangles