Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # import os
  4. import cv2
  5. import numpy as np
  6.  
  7. img = cv2.imread('invMehs.png', -1)
  8.  
  9. imGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  10. ret, imBw = cv2.threshold(imGray, 250, 255, cv2.THRESH_BINARY)
  11.  
  12. # connected components
  13. colorMask = np.ones(img.shape, dtype="uint8") * 255
  14. Mask = np.ones(imBw.shape, dtype="uint8") * 255
  15.  
  16. connectivity = 4
  17. output = cv2.connectedComponentsWithStats(imBw, connectivity, cv2.CV_32S)
  18. num_labels = output[0]
  19. labels = output[1]
  20. stats = output[2]
  21. centroids = output[3]
  22.  
  23. print(labels)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement