title: How to use opencv to individually crop regions of a mask?
body: <p>I have this image of a bunch of circles, all different colors (red, green, yellow, purple, etc.). I would like to individually crop all the red circles and save them as separate files (ex. circle(1).png, circle(2).png, etc.).</p>
  
  <p>What I have so far is a solution to only show the red circles. I created a mask with <code>cv2.inRange</code> and used a <code>cv2.bitwise</code>_and to only show the red circles. Here is my code:</p>
  
  <pre class="lang-py prettyprint-override"><code>import cv2 
  import numpy as np
  
  
  image = cv2.imread('dots.jpg')
  hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
  
  lower_red = np.array([150,100,0])
  upper_red = np.array([255,255,255])
  
   # Threshold the HSV image to get only red cirlces
  mask = cv2.inRange(hsv, lower_red, upper_red)
  
  # Bitwise-AND mask and original image
  res = cv2.bitwise_and(image,image, mask=mask)
  </code></pre>
  
  <p>I guess what I'm looking for is something like <code>cv2.selectROI()</code> but runs automatically (no manual click&amp;drag) and can crop multiple regions. Any ideas or tips appreciated. Thanks</p>