Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions cocoviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,44 @@ def draw_masks(draw, objects, obj_categories, ignore, alpha):

def rle_to_mask(rle, height, width):
rows, cols = height, width
rle_pairs = np.array(rle).reshape(-1, 2)
img = np.zeros(rows * cols, dtype=np.uint8)
index_offset = 0

for index, length in rle_pairs:
index_offset += index
img[index_offset : index_offset + length] = 255
index_offset += length

if type(rle) == str:
m = 0
p = 0
k = 0
str_len = len(rle)
cnts= [0] * str_len
while p < str_len:
x=0
k=0
more=1
while more != 0 :
c= ord(rle[p]) - 48
x |= ((c & 0x1f) << (5*k))
more = c & 0x20
p+=1
k+=1
if p >= str_len-1:
break
if more == 0 and (c & 0x10 != 0):
x |= -1 << 5*k

if(m>2) :
x += cnts[m-2]
cnts[m]=x

if m%2 == 1:
img[index_offset : index_offset + x] = 255
index_offset+=x
m+=1
else:
rle_pairs = np.array(rle).reshape(-1, 2)
for index, length in rle_pairs:
index_offset += index
img[index_offset : index_offset + length] = 255
index_offset += length

img = img.reshape(cols, rows)
img = img.T
Expand Down