title: OpenCV performance on template matching
body: <p>I'm trying to do template matching basically on java. I used straightforward algorithm to find match. Here is the code: </p>
  
  <pre><code>minSAD = VALUE_MAX;
  // loop through the search image
  for ( int x = 0; x &lt;= S_rows - T_rows; x++ ) {
      for ( int y = 0; y &lt;= S_cols - T_cols; y++ ) {
          SAD = 0.0;
  
          // loop through the template image
          for ( int i = 0; i &lt; T_rows; i++ )
              for ( int j = 0; j &lt; T_cols; j++ ) {
  
                  pixel p_SearchIMG = S[x+i][y+j];
  
                  pixel p_TemplateIMG = T[i][j];
  
                  SAD += abs( p_SearchIMG.Grey - p_TemplateIMG.Grey );
              }
      }
  
      // save the best found position 
      if ( minSAD &gt; SAD ) {
          minSAD = SAD;
          // give me VALUE_MAX
          position.bestRow = x;
          position.bestCol = y;
          position.bestSAD = SAD;
      }
  }
  </code></pre>
  
  <p>But this is very slow approach. I tested 2 images (768 × 1280) and subimage (384 x 640). This lasts for ages. 
  Does openCV perform template matching much faster or not with ready function cvMatchTemplate()? </p>