I have a problem with connectedComponents
(or connectedComponentsWithStats
) which is an opencv (3.3.0) function in Python (2.7.12). A simple code is the following :
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]
It returns
[[0 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 0]]
which is strange since I asked for connected components with connectivity 4 (not 8). So the two pixels in (1, 1)
and (2, 2)
are not connected and should give two different connected components, labelled 1 and 2 for instance.
Did I make a mistake ?