Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. imMeshLayer = cv2.imread('testLayer6_.png', -1)
  2. imMesh = cv2.imread('new_refined2__DXF.png', -1)
  3.  
  4. """
  5. binary conversions
  6. """
  7. imGrayMshLayer = cv2.cvtColor(imMeshLayer, cv2.COLOR_BGR2GRAY)
  8. (thresh, imMeshly_bw) = cv2.threshold(imGrayMshLayer, 128, 255,
  9.                                       cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  10.  
  11. imGrayMsh1 = cv2.cvtColor(imMesh, cv2.COLOR_BGR2GRAY)
  12. (thresh, imMesh_bw1) = cv2.threshold(imGrayMsh1, 128, 255,
  13.                                      cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  14.  
  15. # connected components
  16. invBwMesh = cv2.bitwise_not(imMesh_bw1)
  17. cv2.imwrite('invMehs.png', invBwMesh)
  18.  
  19. """
  20. connect components
  21. """
  22. connectivity = 4
  23.  
  24. # Perform the operation
  25. output = cv2.connectedComponentsWithStats(imMesh_bw1, connectivity, cv2.CV_32S)
  26. # Get the results
  27. # The first cell is the number of labels
  28. num_labels = output[0]
  29. # The second cell is the label matrix
  30. labels = output[1]
  31. # The third cell is the stat matrix
  32. stats = output[2]
  33. # The fourth cell is the centroid matrix
  34. centroids = output[3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement