我对connectedComponents
(or connectedComponentsWithStats
) 有疑问,它是 Python (2.7.12) 中的 opencv (3.3.0) 函数。一个简单的代码如下:
import numpy as np
import cv2
img = np.zeros((4,4), dtype = np.uint8)
img[1,1] = 255
img[2,2] = 255
output = cv2.connectedComponents(img, 4)
print output[1]
它返回
[[0 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 0]]
这很奇怪,因为我要求连接组件具有连接 4(不是 8)。(1, 1)
因此和中的两个像素(2, 2)
没有连接,应该给出两个不同的连接分量,例如标记为 1 和 2。
我犯错了吗?