title: Preventing Incorrect Template Matching OpenCV
body: <p>I am using template matching in a project to find all the locations of a <code>subimage</code> in larger images. I am using the <code>OpenCV</code> methods <code>templateMatch()</code> and <code>floodFill()</code> (in Java) to accomplish this, and it is working properly, but only for larger images that DO contain the <code>subimage</code>. </p>
  
  <pre><code>Imgproc.matchTemplate(image, subimage, result, Imgproc.TM_CCOEFF);
  </code></pre>
  
  <p>If the larger image doesn't contain it, I am returned a huge list of incorrect locations. I want all the locations (if the subimage exists in the larger image), but NONE if it doesn't. How should I go about doing this? And if template matching is not the correct way to do it, what way should I do it then?</p>
  
  <p>Btw my code is structured like this <a href="https://stackoverflow.com/questions/31088449/java-opencv-template-matching-and-floodfill-behavior">Java opencv template matching and floodfill behavior.</a></p>
  
  <p>All help is much appreciated!</p>