title: opencv - matchTemplate
body: <p>I am new to opencv.</p>
  
  <p>I have a piece of code that finds a match to my template.</p>
  
  <pre><code> public static void findTemplete(String inFile, String templateFile, String outFile, int match_method) {
      System.out.println("\nRunning Template Matching");
  
      Mat img = Highgui.imread(inFile);
      Mat templ = Highgui.imread(templateFile);
  
      int result_cols = img.cols() - templ.cols() + 1;
      int result_rows = img.rows() - templ.rows() + 1;
      Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
  
      Imgproc.matchTemplate(img, templ, result, match_method);
      Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
  
      MinMaxLocResult mmr = Core.minMaxLoc(result);
  
      Point matchLoc;
      if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) {
          matchLoc = mmr.minLoc;
      } else {
          matchLoc = mmr.maxLoc;
      }
  
      Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
              matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
  
      System.out.println("Writing "+ outFile);
      Highgui.imwrite(outFile, img);
  
  }
  </code></pre>
  
  <p>My problem is that matchTemplate finds "The best match". So if my templete doesnt exists at all in the picture it finds something anyhow.</p>
  
  <p>So how can i set the "Match strength", so that only strong matches will be found.</p>