Guest User

Untitled

a guest
Aug 9th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import cv2
  4. import numpy as np
  5.  
  6. # mesh image
  7. imMesh = cv2.imread('new_refined2__DXF.png', -1)
  8.  
  9. # layer image
  10. imLayer1 = cv2.imread('Layer1.png', -1)
  11.  
  12. """
  13. binary conversions
  14. """
  15. imMeshGray = cv2.cvtColor(imMesh, cv2.COLOR_BGR2GRAY)
  16. ret, imMeshBw = cv2.threshold(imMeshGray, 250, 255, cv2.THRESH_BINARY)
  17.  
  18. imLayer1Gray = cv2.cvtColor(imLayer1, cv2.COLOR_BGR2GRAY)
  19. (thresh, imLayerBw) = cv2.threshold(imLayer1Gray, 128, 255,
  20.                                     cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  21.  
  22. connectivity = 4
  23.  
  24. output = cv2.connectedComponentsWithStats(imMeshBw, connectivity, cv2.CV_32S)
  25. num_labels = output[0]
  26. labels = output[1]
  27. stats = output[2]
  28.  
  29. centroids = output[3]
  30. # labels = labels + 1
  31.  
  32. print(labels)
  33. print(num_labels)
  34.  
  35. # if I want for each label
  36. for label in np.unique(labels):
  37.     if label == 0:
  38.         continue
  39.     mask = np.zeros(imMeshGray.shape, dtype="uint8")
  40.     # I should do here the bitwise, however I have a problem with my "triangles"
  41.  
  42.     mask[labels == label] = 255
  43.  
  44. cv2.imwrite('tst.jpg', mask)
Add Comment
Please, Sign In to add comment