Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import cv2
- import numpy as np
- # mesh image
- imMesh = cv2.imread('new_refined2__DXF.png', -1)
- # layer image
- imLayer1 = cv2.imread('Layer1.png', -1)
- """
- binary conversions
- """
- imMeshGray = cv2.cvtColor(imMesh, cv2.COLOR_BGR2GRAY)
- ret, imMeshBw = cv2.threshold(imMeshGray, 250, 255, cv2.THRESH_BINARY)
- imLayer1Gray = cv2.cvtColor(imLayer1, cv2.COLOR_BGR2GRAY)
- (thresh, imLayerBw) = cv2.threshold(imLayer1Gray, 128, 255,
- cv2.THRESH_BINARY | cv2.THRESH_OTSU)
- connectivity = 4
- output = cv2.connectedComponentsWithStats(imMeshBw, connectivity, cv2.CV_32S)
- num_labels = output[0]
- labels = output[1]
- stats = output[2]
- centroids = output[3]
- # labels = labels + 1
- print(labels)
- print(num_labels)
- # if I want for each label
- for label in np.unique(labels):
- if label == 0:
- continue
- mask = np.zeros(imMeshGray.shape, dtype="uint8")
- # I should do here the bitwise, however I have a problem with my "triangles"
- mask[labels == label] = 255
- cv2.imwrite('tst.jpg', mask)
Add Comment
Please, Sign In to add comment