Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # import os
- 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)
- # connected components
- invBwMesh = cv2.bitwise_not(imBw)
- colorMask = np.ones(img.shape, dtype="uint8") * 255
- # Mask = np.ones(imBw.shape, dtype="uint8") * 255
- # print(Mask.shape)
- 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
- # if I want for each label
- for label in np.unique(labels):
- mask = np.zeros(imGray.shape, dtype="uint8")
- # however it will only visible the last component, because I just have one mask variable
- mask[labels == label] = 255
- cv2.imwrite('tst.jpg', mask)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement