title: Template matching in openCV [JAVA]
body: <p>I am using <strong>OpenCV(opencv_java248)</strong>. I have one template image. This template image have logo some company. I want to know if this logo contain in other image. I got following code somewhere.</p>
  
  <pre><code>public void run(String inFile, String templateFile, String outFile,
          int match_method) {
      System.out.println("Running Template Matching");
  
      Mat img = Highgui.imread(inFile);
      Mat templ = Highgui.imread(templateFile);
  
      // / Create the result matrix
      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);
  
      // / Do the Matching and Normalize
      Imgproc.matchTemplate(img, templ, result, match_method);
      // Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new
      // Mat());
      Imgproc.threshold(result, result, 0.5, 1.0, Imgproc.THRESH_TOZERO);
      // / Localizing the best match with minMaxLoc
      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;
      }
      double threashhold = 0.40;
      if (mmr.maxVal &gt; threashhold) {
          Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
                  matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
      }
      // Save the visualized detection.
      Highgui.imwrite(outFile, img);
  }
  </code></pre>
  
  <p>It is working great when template and target image is of same scale. My question is how can I make it scale irrelevant ?
  My search image <a href="https://i.stack.imgur.com/rHL3c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rHL3c.png" alt="Target Image "></a> and logo <a href="https://i.stack.imgur.com/1negw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1negw.png" alt="Template"></a></p>