title: opencv python connectedComponents select component per label
body: <p>I want to select each component of this image :</p>
  
  <p><a href="https://i.stack.imgur.com/btgid.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/btgid.png" alt="enter image description here"></a></p>
  
  <p>In practice, each and every triangle, by its labels. I don't figure out how.
  I have this code:</p>
  
  <pre><code>#!/usr/bin/python
  import cv2
  import numpy as np
  img = cv2.imread('invMehs.png', -1)
  imGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  ret, imBw = cv2.threshold(imGray, 250, 255, cv2.THRESH_BINARY)
  
  invBwMesh = cv2.bitwise_not(imBw)
  Mask = np.ones(imBw.shape, dtype="uint8") * 255
  
  connectivity = 4
  output = cv2.connectedComponentsWithStats(imBw, connectivity, cv2.CV_32S)
  num_labels = output[0]
  labels = output[1]
  stats = output[2]
  centroids = output[3]
  labels = labels + 1
  
  b = ( labels == 1)
  cv2.imwrite('tst.jpg',labels[b])
  </code></pre>
  
  <p>But the image is complety black :S
  Thank you very much.</p>