这是因为
cv2.connectedComponents()仅将白色部分视为分量。因此,您将获得一个组件。
您必须反转图像。您可以通过使用
cv2.bitwise_not()函数来实现。
码:
import cv2import numpy as npimg = cv2.imread('cc.png', 0)ret, thresh = cv2.threshold(img, 127, 255, 0)#---- Inverting the image here ----img = cv2.bitwise_not(thresh) _, markers = cv2.connectedComponents(img)print np.amax(markers)
结果:
19
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)