title: Detecting All Occurrences of Subimage Within Image
body: <p>Recently, I've been developing a small side project that needs the ability to find the X &amp; Y coordinates of a subimage within another image. The images might be in different resolutions, but overall the image resolutions will be similar and the colors should be the same. I have looked into OpenCV, but it seems that OpenCV only returns a single match. I need to find all occurrences/instances of the subimage inside of the super-image. I already have all of the subimages to search for, so I am only in need of a way to find the coordinates of the subimages within the super-image.</p>
  
  <p>Here's an example of what I mean:</p>
  
  <p>If we have <code>red_circle.png</code>:</p>
  
  <p><img src="https://i.imgur.com/KbwMebLm.png" alt="Red Circle Subimage"></p>
  
  <p>and <code>shapes.png</code>:</p>
  
  <p><img src="https://i.imgur.com/Tfl3wazm.png" alt="Shapes Super-Image"></p>
  
  <p>I need to get the X &amp; Y coordinates for <strong>all</strong> of the red circles (<code>red_circle.png</code>; subimage) within the picture of various shapes (<code>shapes.png</code>; super-image).</p>
  
  <p>Ideally, I would like to be able to do something like this:</p>
  
  <pre><code>/* code to read in red_cirlce.png and shapes.png as BufferedImages */
  ArrayList&lt;Point&gt; instancesOfRedCircle = new ArrayList&lt;&gt;();
  findAllSubimageInstances( shapesObj, // Super-Image
                            redCircleObj, // Subimage
                            instancesOfRedCircle // ArrayList to put points in
                          );
  </code></pre>
  
  <p>Does anybody know of a way to do this (eg, a library, a function, etcetera)?</p>