title: How to obtain (x,y) coordinates of a shape found using mask in OpenCV, Python?
body: <p>I am trying to locate certain items on an image. The image in simplified form looks like this:
  <a href="https://i.stack.imgur.com/DmkOg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DmkOg.png" alt="enter image description here" /></a></p>
  <p>I would like to obtain the (x,y) coordinates of the bold black text on top of the second rectangle, as well as of the three colored rectangles.</p>
  <p>I have the masks ready, except for the mask of the black text that I wasn't able to figure out. However, the text is always on top of the rectangle so if I'd be able to figure out the position of the bottom large rectangle, I would have the position of the text too.</p>
  <p>These are the outputs I got:
  <a href="https://i.stack.imgur.com/lzEJQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lzEJQ.png" alt="enter image description here" /></a></p>
  <p>I tried using the ConnectedComponents function based on <a href="https://stackoverflow.com/a/46442154/5123111">this comment</a> but apart from coloring and grouping the various objects, I didn't manage to move forward, so I didn't include that snippet below to make things as clear as possible.</p>
  <p>Here is my code so far:</p>
  <pre><code>import cv2
  import numpy as np
  import imutils
  
  PATH = &quot;stackoverflow.png&quot;
  img = cv2.imread(PATH)
  imgHSV = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
  
  mask_border = cv2.inRange(imgHSV,np.array([0,0,170]),np.array([0,0,175]))
  mask_green  = cv2.inRange(imgHSV,np.array([76,221,167]),np.array([76,221,167]))
  mask_pink   = cv2.inRange(imgHSV,np.array([168,41,245]),np.array([172,41,252]))
  mask_red    = cv2.inRange(imgHSV,np.array([4,207,251]),np.array([4,207,251]))
  #mask_black  = ???
  
  all_masks = cv2.bitwise_or(mask_border, mask_green)
  all_masks = cv2.bitwise_or(all_masks, mask_pink)
  all_masks = cv2.bitwise_or(all_masks, mask_red)
  
  cv2.imshow(&quot;Masks&quot;, all_masks)
  
  imgResult = cv2.bitwise_and(img,img,mask=all_masks)
  
  cv2.imshow(&quot;Output&quot;, imgResult)
  
  cv2.waitKey(0)
  
  </code></pre>