title: Multiple template matching only detects one match
body: <p>I'm trying to match this image</p>
  
  <p><a href="https://i.stack.imgur.com/JuL4H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JuL4H.png" alt="enter image description here"></a></p>
  
  <p>in this image </p>
  
  <p><a href="https://i.stack.imgur.com/M7W1P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M7W1P.png" alt="enter image description here"></a></p>
  
  <p>However, I can't find more than one boss enemy. What do I need to do to find the others? </p>
  
  <p><strong>Image Loading</strong></p>
  
  <pre><code>struct XYposition{
    float X;
    float Y;
  };
  
  std::vector&lt;cv::Mat&gt; bossList;
  std::string bossStrings[1] = { "sprites\\boss\\bossUp.png" };
  for (int i = 0; i &lt; 1; i++){
      cv::Mat pic = cv::imread(bossStrings[i], CV_LOAD_IMAGE_GRAYSCALE);
      bossList.push_back(pic);
  }
  
  multipleTemplateMatch(screenImage, bossList);
  </code></pre>
  
  <p><strong>Template Matching</strong></p>
  
  <pre><code>std::vector&lt;XYposition&gt; multipleTemplateMatch(cv::Mat &amp;img, std::vector&lt;cv::Mat&gt; tplList){
  
  std::vector&lt;XYposition&gt; matches;
  
  cv::Mat convertImg(img.rows, img.cols, CV_8UC3);
  cv::cvtColor(img, convertImg, CV_BGRA2GRAY);
  
  double threshold = 0.8;
  
  int imgint = convertImg.type();
  
  for(cv::Mat tpl : tplList){
      int tplint = tpl.type();
      cv::Mat result(convertImg.rows - tpl.rows + 1, convertImg.cols - tpl.cols + 1,
          CV_32FC1); //must be this result type
  
  
      cv::matchTemplate(convertImg, tpl, result, CV_TM_CCOEFF_NORMED);
      cv::threshold(result, result, threshold, 1., CV_THRESH_TOZERO);
  
      while (true)
      {
          double minval, maxval;
          cv::Point minloc, maxloc;
          cv::minMaxLoc(result, &amp;minval, &amp;maxval, &amp;minloc, &amp;maxloc);
          if (maxval &gt;= threshold)
          {
              rectangle(result, maxloc, cv::Point(maxloc.x - tpl.cols, maxloc.y - tpl.rows),
                  cv::Scalar(0, 0, 255), 4, 8, 0);
              cv::floodFill(result, maxloc, cv::Scalar(0), 0, cv::Scalar(.1), cv::Scalar(1.));
  
              XYposition info = {
                  maxloc.x - ceil(tpl.cols / 2), maxloc.y - ceil(tpl.rows / 2)
              };
              matches.push_back(info);
          }
          else
              break;
      }
  }
  
  return matches;
  }
  </code></pre>