title: OpenCV - how many black objects are there in a photo?
body: <p>Okay, so I'm trying openCV with c++, and I want to do a simple detection program for objects that are black colored. So I have this simple code:</p>
  
  <pre><code>int main()
  {
      Mat3b bgr = imread("C:/Users/sesoa/Desktop/photos/shapes.png");
  
      Mat3b hsv;
      cvtColor(bgr, hsv, COLOR_BGR2HSV);
  
      Mat1b mask1, mask2;
      inRange(hsv, Scalar(0, 0, 0, 0), Scalar(180, 255, 30, 0), mask1);
      inRange(hsv, Scalar(0, 0, 0, 0), Scalar(180, 255, 40, 0), mask2);
  
  
  
      Mat1b mask = mask1 | mask2;
  
      imshow("Mask", mask);
      waitKey();
  
      return 0;
  }
  </code></pre>
  
  <p>shapes.png is this:
  <a href="https://i.stack.imgur.com/aZpD6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aZpD6.png" alt="enter image description here"></a></p>
  
  <p>all the shapes are rounded with color black. I would like for my program to tell me how many of connected black objects are there. Also the writing under the shapes is also black. So It shows me this as well, that's okay, cause this is a test photo anyway. </p>
  
  <p>How can I modify my program to detect how many connected black objects are in the photo? (In this photo, the output should be "60" as there are 8 objects and 49 letters + 3 letters are 'i' so we have to count the dots).</p>
  
  <p>EDIT:</p>
  
  <p>I want the program to count black objects. I already get all black objects out like this:
  <a href="https://i.stack.imgur.com/m2oS9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m2oS9.png" alt="enter image description here"></a></p>