kys92
kys92

Reputation: 73

cv.fillPoly generating zero arrays, not reading inputs

I have

blank = np.zeros(shape = im.shape, dtype = np.float32)

which generates

array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)

I have [label2poly[label]] which is dtype('int32')

[array([[ 716,    1],
        [ 710,  281],
        [ 727,  322],
        [ 756,  369],
        [ 793,  399],
        [ 863,  406],
        [ 952,  416],
        [ 978,  412],
        [ 416,    1]])]

When I try cv2.fillPoly(blank, [label2poly[label]], 255) it outputs

array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.]], dtype=float32)`

where it should have been something like

array([[  0.,   0.,   0., ...,   0.,   0.,   0.],
       [  0.,   0., 255., ...,   0.,   0.,   0.],
       [  0.,   0., 255., ...,   0.,   0.,   0.],
       ...,
       [  0., 255., 255., ..., 255., 255., 255.],
       [  0., 255., 255., ...,   0.,   0.,   0.],
       [  0.,   0.,   0., ...,   0.,   0.,   0.]], dtype=float32)

I am trying to create multiple masks. Would appreciate any help.

Upvotes: 1

Views: 61

Answers (1)

karlphillip
karlphillip

Reputation: 93468

Initialization of blank:

blank = np.zeros(shape=[5, 5], dtype=np.float32)
print(blank)

Output:

[[0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]]

Initialization of label followed by a call to fillPoly() which uses is as a mask to fill blank with 255 at specific positions:

label = np.array([[[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]], dtype=np.int32)

cv2.fillPoly(blank, [label], 255)
print(blank)

Output:

[[  0.   0.   0.   0.   0.]
 [  0. 255. 255. 255.   0.]
 [  0. 255. 255. 255.   0.]
 [  0. 255. 255. 255.   0.]
 [  0.   0.   0.   0.   0.]]

Upvotes: 1

Related Questions