cv2.connectedComponents未检测到组件

cv2.connectedComponents未检测到组件,第1张

cv2.connectedComponents未检测到组件

这是因为

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5668591.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存