-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
rle2polygons.py
113 lines (99 loc) · 23.2 KB
/
rle2polygons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import cv2
import numpy as np
from pycocotools import mask
def is_clockwise(contour):
value = 0
num = len(contour)
for i, point in enumerate(contour):
p1 = contour[i]
if i < num - 1:
p2 = contour[i + 1]
else:
p2 = contour[0]
value += (p2[0][0] - p1[0][0]) * (p2[0][1] + p1[0][1]);
return value < 0
def get_merge_point_idx(contour1, contour2):
idx1 = 0
idx2 = 0
distance_min = -1
for i, p1 in enumerate(contour1):
for j, p2 in enumerate(contour2):
distance = pow(p2[0][0] - p1[0][0], 2) + pow(p2[0][1] - p1[0][1], 2);
if distance_min < 0:
distance_min = distance
idx1 = i
idx2 = j
elif distance < distance_min:
distance_min = distance
idx1 = i
idx2 = j
return idx1, idx2
def merge_contours(contour1, contour2, idx1, idx2):
contour = []
for i in list(range(0, idx1 + 1)):
contour.append(contour1[i])
for i in list(range(idx2, len(contour2))):
contour.append(contour2[i])
for i in list(range(0, idx2 + 1)):
contour.append(contour2[i])
for i in list(range(idx1, len(contour1))):
contour.append(contour1[i])
contour = np.array(contour)
return contour
def merge_with_parent(contour_parent, contour):
if not is_clockwise(contour_parent):
contour_parent = contour_parent[::-1]
if is_clockwise(contour):
contour = contour[::-1]
idx1, idx2 = get_merge_point_idx(contour_parent, contour)
return merge_contours(contour_parent, contour, idx1, idx2)
def mask2polygon(image):
contours, hierarchies = cv2.findContours(image, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS)
contours_approx = []
polygons = []
for contour in contours:
epsilon = 0.001 * cv2.arcLength(contour, True)
contour_approx = cv2.approxPolyDP(contour, epsilon, True)
contours_approx.append(contour_approx)
contours_parent = []
for i, contour in enumerate(contours_approx):
parent_idx = hierarchies[0][i][3]
if parent_idx < 0 and len(contour) >= 3:
contours_parent.append(contour)
else:
contours_parent.append([])
for i, contour in enumerate(contours_approx):
parent_idx = hierarchies[0][i][3]
if parent_idx >= 0 and len(contour) >= 3:
contour_parent = contours_parent[parent_idx]
if len(contour_parent) == 0:
continue
contours_parent[parent_idx] = merge_with_parent(contour_parent, contour)
contours_parent_tmp = []
for contour in contours_parent:
if len(contour) == 0:
continue
contours_parent_tmp.append(contour)
polygons = []
for contour in contours_parent_tmp:
polygon = contour.flatten().tolist()
polygons.append(polygon)
return polygons
if __name__ == '__main__':
is_compressed_rle = True
if(is_compressed_rle):
segmentation = {
"counts": "[dVV67Pn2;F:F:G9K5J6K3L3N2M2O2M3O1N2N2O1N2N2N2O1N2N2N2N2O1N2N2N2N2N2O1N2N2N2N2N2O1N2N2N2N2N2O2M2N2N2O1N2O1N2O1N2O1N2O1N2O1N2O1N2O1N2O1N2O1N2N2O001N2O1N2O1O0O2O1N2O1O1N2O001N2O1N2O1O0O2O1N2O1O1N101O1N2O1N101O1N2O0O2O1O1N101O1N101N2O1O0O2O1N2O001N2O1O0O2O1N2O001N2O0O2O001N101O0O2O001N101O001N101O0O2O001N101O001N101O0O2O000O2O001nZMQHcc2o7W\\M[Hdc2g7T\\MeHgc2[7R\\MQIic2P7P\\MZIkc2g6n[MeImc2c8K4K3N1O1O1O2M2O1O1O2M2O1O2N1N2O1O2N0O1000000O101O00000O1000000O2O00000O1000000O2O0000000O1000000O2O00000O1000000O2O0000000O1O001N1O101N1O100O2N100O2N1O101O01O100O00100O001O1O1O0O2O1O001O1O1N101O1O1O001N2O0O2N2N2N1O2N2N2UOT]MRFmb2o9[]MfEhb2Z:f00O1000000O100001O0001O0001O000000000010O0000001O01O01O0000010O00001O0001O01O00010O01O0010O01O001O001O001O001O10O01O001O001O001O001O0010O01O001O001O1O001O001O002O0O1O2N1O1010O1O10O01O100O1O010O0001N10001N10001O0O=DO10O10O10O01000O0100O01000O010O01000O010O10O10O010O10O010O10O10O010O10O10O010O10O10O010O10O1O00000000000000001O0000000000000000000000001O0000000000000001O000000000000000O100000000O1000001O0O1000001O0O100000001N1000000O101O00000O1O1M4nMiZMiJYe2W5hZMfJZe2[5gZM`J\\e2`5eZM]J]e2c5eZMXJ^e2h5cZMUJ`e2j5bZMQJae2o5`ZMnIbe2S6_ZMiIce2W6^ZMeIee2[6]ZMaIee2_6V1O0001O000001O0010O0001O001j0UO3N1N2O2M2N10O0010O01O0O2M2O2N1N2J7G8I8G8SLbXMc0fg2[O[XM>lg2AUXM:Qh2DPXM9Sh2FoWM6Uh2HlWM4Xh2KiWM2Zh2NfWMO^h2OdWMM_h22bWMKbh23_WMKch24^WMJeh24]WMIeh26\\WMHgh26ZWMHhh27ZWMFih28XWMElh2:TWMDnh2;TWMBoh2<RWMBQi2<QWMARi2=oVMATi2=nVM@Ti2?mVM_OVi2?lVM^OWi2?kVM_OXi2?jVM]OZi2a0fVM^O]i2?eVM_O]i2`0dVM^O_i2`0aVM_Obi2>`VMAbi2=^VMCdi2;]VMDdi2:^VMEdi29\\VMGfi27[VMHgi25[VMJgi24[VMJfi25\\VMIfi24\\VMKhi21ZVMMoi2JSVM4Uj2CnUM;Sl2O2N2K5KRbTa5",
"size": [3022, 4666]
}
else:
segmentation = {
"counts": [786329, 17, 1183, 36, 1164, 56, 1144, 75, 1125, 94, 1106, 113, 1087, 132, 1068, 151, 1049, 171, 1029, 189, 1011, 209, 991, 228, 972, 247, 953, 266, 934, 286, 914, 305, 895, 324, 876, 343, 857, 363, 837, 375, 824, 376, 824, 376, 824, 376, 824, 376, 824, 376, 824, 376, 824, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 375, 825, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 825, 375, 825, 375, 825, 375, 825, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 374, 826, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 372, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 373, 827, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 371, 829, 371, 829, 371, 829, 371, 829, 371, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 372, 828, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 371, 829, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 370, 830, 244, 46, 80, 830, 244, 67, 59, 830, 244, 67, 59, 830, 244, 67, 59, 830, 244, 66, 60, 830, 244, 67, 59, 830, 244, 67, 58, 831, 244, 67, 58, 831, 244, 66, 59, 831, 244, 66, 59, 831, 244, 65, 60, 831, 243, 66, 60, 831, 243, 66, 60, 831, 243, 66, 60, 831, 243, 64, 62, 831, 243, 64, 62, 831, 243, 63, 63, 831, 243, 63, 63, 831, 243, 63, 63, 830, 244, 60, 66, 830, 244, 60, 66, 830, 244, 60, 65, 831, 244, 60, 65, 831, 244, 59, 66, 831, 244, 59, 66, 831, 244, 60, 65, 831, 244, 60, 65, 831, 244, 60, 65, 831, 244, 60, 65, 831, 244, 60, 65, 831, 244, 58, 67, 831, 243, 59, 67, 831, 243, 59, 67, 831, 243, 59, 67, 831, 243, 59, 67, 831, 243, 59, 67, 831, 243, 59, 67, 831, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 58, 67, 832, 243, 58, 67, 832, 243, 58, 67, 832, 242, 59, 67, 832, 242, 59, 67, 832, 242, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 59, 66, 832, 243, 58, 67, 832, 243, 58, 67, 832, 243, 58, 67, 832, 243, 58, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 58, 67, 833, 242, 58, 67, 833, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 59, 66, 833, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 65, 835, 241, 59, 65, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 242, 58, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 66, 834, 241, 59, 65, 835, 241, 59, 65, 835, 241, 59, 65, 835, 241, 59, 65, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 240, 59, 65, 836, 240, 59, 65, 836, 240, 59, 65, 836, 240, 59, 65, 836, 240, 59, 65, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 66, 835, 241, 58, 65, 836, 241, 58, 65, 836, 241, 58, 65, 836, 241, 58, 65, 836, 240, 59, 65, 836, 240, 59, 65, 836, 240, 59, 65, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 66, 836, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 239, 59, 65, 837, 239, 59, 65, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 240, 58, 65, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 66, 837, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 57, 66, 838, 239, 57, 66, 838, 239, 57, 66, 838, 238, 58, 66, 838, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 58, 65, 838, 239, 57, 66, 838, 239, 57, 66, 838, 239, 57, 65, 839, 239, 57, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 237, 58, 65, 840, 237, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 65, 839, 238, 58, 64, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 238, 57, 65, 840, 237, 58, 65, 840, 237, 58, 65, 840, 237, 58, 65, 840, 237, 58, 65, 840, 237, 58, 65, 840, 237, 58, 65, 840, 237, 58, 64, 841, 237, 58, 64, 841, 237, 58, 64, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 840, 238, 57, 65, 840, 237, 58, 65, 840, 237, 58, 65, 840, 237, 58, 65, 840, 237, 58, 64, 841, 237, 58, 64, 841, 237, 58, 64, 841, 237, 58, 64, 841, 237, 58, 64, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 65, 841, 237, 57, 64, 842, 236, 58, 64, 842, 236, 58, 64, 842, 236, 58, 64, 842, 236, 58, 64, 842, 236, 58, 64, 842, 236, 58, 64, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 841, 237, 57, 64, 842, 237, 57, 64, 842, 237, 57, 64, 842, 237, 57, 64, 842, 237, 57, 64, 842, 236, 58, 64, 842, 236, 58, 64, 842, 236, 58, 64, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 65, 842, 236, 57, 64, 843, 236, 57, 64, 843, 236, 57, 64, 843, 236, 57, 64, 843, 236, 57, 64, 843, 236, 57, 64, 843, 236, 57, 64, 843, 236, 57, 64, 843, 235, 58, 64, 843, 235, 58, 64, 843, 235, 57, 65, 843, 235, 57, 65, 843, 235, 57, 65, 843, 235, 57, 65, 843, 235, 57, 65, 843, 235, 57, 65, 843, 235, 57, 64, 844, 235, 57, 64, 844, 235, 57, 64, 844, 235, 57, 64, 843, 236, 56, 65, 843, 236, 45, 76, 843, 236, 45, 76, 843, 236, 45, 76, 843, 236, 45, 76, 843, 236, 45, 76, 843, 236, 45, 76, 843, 236, 45, 76, 843, 237, 38, 1, 3, 78, 843, 239, 34, 84, 843, 240, 28, 1, 3, 85, 843, 243, 16, 1, 8, 89, 843, 252, 1, 103, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 356, 844, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 355, 845, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 845, 355, 845, 355, 845, 355, 845, 355, 845, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 354, 846, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 846, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 353, 847, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 351, 849, 351, 849, 351, 849, 351, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 352, 848, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 351, 849, 350, 850, 350, 850, 350, 850, 350, 850, 350, 850, 350, 850, 350, 850, 350, 849, 351, 849, 351, 849, 351, 849, 351, 849, 290, 7, 54, 849, 281, 16, 54, 849, 272, 25, 54, 849, 263, 32, 56, 849, 254, 40, 56, 850, 245, 49, 56, 850, 236, 57, 57, 850, 231, 61, 58, 850, 231, 61, 58, 850, 231, 59, 60, 850, 231, 58, 61, 850, 231, 58, 61, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 55, 63, 851, 231, 55, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 63, 850, 231, 56, 62, 851, 231, 56, 62, 851, 231, 55, 63, 851, 231, 55, 63, 851, 231, 55, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 63, 851, 230, 56, 62, 852, 230, 56, 62, 852, 230, 56, 62, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 229, 56, 63, 852, 229, 56, 63, 852, 229, 56, 63, 852, 229, 56, 63, 852, 229, 56, 63, 852, 229, 56, 63, 851, 230, 56, 63, 851, 230, 56, 62, 852, 230, 56, 62, 852, 230, 56, 62, 852, 230, 56, 62, 852, 230, 56, 62, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 230, 55, 63, 852, 229, 56, 63, 852, 229, 56, 63, 852, 229, 56, 63, 852, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 228, 56, 62, 854, 228, 56, 62, 854, 228, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 56, 62, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 63, 853, 229, 55, 62, 854, 229, 55, 62, 854, 229, 55, 62, 854, 229, 55, 62, 854, 228, 56, 62, 854, 228, 56, 62, 854, 228, 56, 62, 854, 228, 56, 62, 854, 228, 56, 62, 854, 228, 56, 62, 854, 228, 55, 63, 854, 228, 55, 63, 854, 228, 55, 63, 854, 228, 55, 63, 854, 228, 55, 63, 854, 228, 55, 63, 854, 228, 55, 62, 855, 228, 55, 62, 855, 228, 55, 62, 855, 228, 55, 62, 855, 228, 55, 62, 855, 228, 55, 62, 855, 228, 55, 62, 855, 228, 55, 62, 855, 227, 56, 62, 856, 226, 56, 62, 856, 226, 56, 62, 857, 225, 56, 62, 857, 225, 55, 63, 858, 224, 55, 63, 858, 224, 55, 63, 859, 223, 55, 63, 859, 223, 55, 62, 861, 222, 55, 62, 861, 222, 55, 62, 862, 221, 55, 62, 862, 221, 55, 62, 862, 221, 55, 62, 863, 220, 55, 62, 863, 220, 55, 62, 864, 219, 55, 62, 864, 219, 55, 62, 865, 218, 55, 62, 865, 217, 56, 62, 866, 216, 56, 62, 866, 216, 56, 62, 867, 215, 55, 63, 867, 215, 55, 63, 868, 214, 55, 62, 869, 214, 55, 62, 870, 213, 55, 62, 870, 213, 55, 62, 871, 212, 55, 62, 871, 212, 55, 62, 872, 211, 55, 62, 872, 211, 55, 62, 873, 210, 55, 62, 873, 210, 55, 62, 874, 209, 55, 62, 874, 209, 55, 62, 875, 208, 55, 62, 875, 208, 55, 62, 876, 207, 55, 62, 876, 206, 55, 63, 877, 205, 55, 62, 878, 205, 55, 62, 879, 204, 55, 62, 879, 204, 55, 62, 880, 203, 55, 62, 880, 203, 55, 62, 881, 202, 55, 62, 881, 202, 55, 62, 882, 201, 55, 62, 882, 201, 55, 62, 883, 1, 7, 192, 55, 62, 891, 192, 55, 62, 891, 192, 55, 62, 891, 192, 55, 62, 891, 192, 55, 62, 891, 192, 55, 62, 891, 192, 55, 61, 892, 192, 54, 62, 892, 192, 54, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 892, 191, 55, 62, 893, 190, 55, 62, 893, 190, 55, 62, 894, 189, 55, 62, 894, 189, 55, 61, 896, 188, 55, 61, 896, 188, 55, 61, 897, 187, 54, 62, 897, 187, 54, 62, 898, 186, 54, 62, 898, 185, 55, 62, 899, 184, 55, 62, 899, 184, 55, 62, 900, 183, 55, 62, 900, 183, 55, 62, 901, 182, 55, 62, 901, 182, 55, 62, 902, 181, 55, 62, 902, 181, 55, 62, 903, 180, 55, 62, 903, 180, 55, 61, 905, 179, 55, 61, 905, 179, 55, 61, 906, 178, 55, 61, 906, 178, 55, 61, 907, 177, 54, 62, 907, 177, 54, 62, 908, 176, 54, 62, 908, 176, 54, 62, 909, 175, 54, 62, 909, 174, 55, 62, 910, 173, 55, 62, 910, 173, 55, 62, 911, 172, 55, 62, 911, 172, 55, 62, 912, 171, 55, 61, 913, 171, 55, 61, 914, 170, 55, 61, 914, 6, 4, 160, 55, 61, 923, 161, 55, 61, 923, 161, 55, 61, 923, 161, 55, 61, 923, 161, 54, 62, 923, 161, 54, 62, 923, 161, 54, 62, 923, 161, 54, 62, 923, 161, 54, 62, 923, 161, 54, 62, 923, 161, 54, 62, 923, 161, 54, 62, 923, 160, 55, 62, 923, 160, 55, 61, 924, 160, 55, 61, 924, 160, 55, 61, 924, 160, 55, 61, 924, 160, 55, 61, 924, 160, 55, 61, 924, 160, 55, 61, 925, 159, 55, 61, 925, 159, 55, 61, 926, 158, 54, 62, 926, 158, 54, 62, 927, 157, 54, 62, 927, 157, 54, 62, 928, 156, 54, 62, 928, 156, 54, 62, 929, 155, 54, 62, 929, 155, 54, 61, 931, 154, 54, 61, 931, 153, 55, 61, 932, 152, 55, 61, 932, 152, 55, 61, 933, 151, 55, 61, 933, 151, 55, 61, 934, 150, 55, 61, 934, 150, 55, 61, 935, 149, 55, 61, 935, 149, 55, 61, 936, 148, 54, 62, 936, 148, 54, 62, 937, 147, 54, 62, 937, 147, 54, 62, 938, 146, 54, 62, 938, 146, 54, 61, 940, 145, 54, 61, 940, 145, 54, 61, 941, 144, 54, 61, 941, 144, 54, 61, 942, 143, 54, 61, 942, 142, 55, 61, 943, 141, 55, 61, 943, 141, 55, 61, 944, 140, 55, 61, 944, 140, 55, 61, 945, 139, 55, 61, 945, 139, 54, 62, 946, 138, 54, 62, 946, 138, 54, 62, 946, 138, 54, 62, 947, 137, 54, 61, 948, 137, 49, 66, 949, 136, 45, 70, 949, 136, 45, 70, 950, 135, 45, 70, 950, 135, 45, 70, 951, 134, 45, 70, 951, 134, 44, 71, 952, 133, 44, 71, 952, 133, 44, 71, 953, 131, 45, 71, 953, 131, 45, 71, 954, 130, 45, 71, 954, 130, 45, 71, 955, 130, 44, 71, 955, 130, 43, 72, 956, 130, 42, 71, 957, 130, 42, 71, 958, 130, 42, 70, 958, 131, 41, 70, 959, 130, 38, 73, 959, 131, 37, 73, 960, 130, 36, 74, 960, 8, 4, 120, 34, 74, 961, 1, 10, 120, 34, 74, 972, 121, 27, 80, 971, 125, 15, 2, 1, 86, 971, 129, 5, 95, 971, 229, 971, 229, 971, 229, 971, 229, 971, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 972, 228, 973, 227, 973, 227, 974, 225, 975, 225, 976, 224, 976, 224, 976, 224, 977, 223, 977, 223, 978, 222, 978, 222, 979, 221, 979, 221, 980, 220, 980, 220, 981, 219, 981, 219, 982, 218, 982, 217, 984, 216, 984, 216, 985, 215, 985, 215, 986, 214, 986, 214, 987, 213, 987, 213, 988, 212, 988, 212, 989, 211, 989, 211, 990, 210, 990, 210, 991, 209, 991, 208, 993, 207, 993, 207, 994, 206, 994, 206, 995, 205, 995, 205, 996, 204, 996, 204, 997, 203, 997, 203, 998, 202, 998, 202, 999, 201, 999, 201, 1000, 200, 1000, 12, 2, 185, 1002, 6, 7, 185, 1002, 1, 12, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 184, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1015, 185, 1016, 184, 1016, 184, 1017, 183, 1017, 183, 1018, 181, 1019, 181, 1020, 180, 1020, 180, 1021, 179, 1021, 179, 1022, 178, 1022, 178, 1023, 177, 1023, 177, 1024, 176, 1024, 176, 1025, 175, 1025, 175, 1026, 174, 1026, 174, 1027, 172, 1028, 172, 1029, 171, 1029, 171, 1030, 170, 1030, 170, 1031, 169, 1031, 169, 1032, 168, 1032, 168, 1032, 168, 1033, 167, 1033, 167, 1034, 166, 1034, 166, 1035, 165, 1035, 164, 1037, 163, 1037, 163, 1038, 162, 1038, 162, 1039, 161, 1039, 161, 1040, 160, 1040, 160, 1041, 159, 1041, 159, 1042, 158, 1042, 158, 1043, 157, 1043, 157, 1044, 156, 1044, 155, 1046, 154, 1046, 154, 1047, 153, 1047, 153, 1048, 152, 1048, 152, 1049, 151, 1049, 150, 1051, 145, 1055, 140, 1061, 135, 1065, 131, 1070, 125, 1075, 121, 1080, 115, 1085, 111, 1090, 105, 1095, 101, 1100, 95, 1105, 91, 1110, 85, 1115, 81, 1120, 75, 1125, 71, 1130, 65, 1135, 61, 1140, 55, 1145, 51, 1149, 46, 1155, 41, 1159, 36, 1165, 31, 1169, 26, 1175, 21, 1179, 16, 1185, 11, 1189, 6, 1195, 1, 33107],
"size": [1200, 1944]
}
if isinstance(segmentation["counts"], list):
segmentation = mask.frPyObjects(segmentation, *segmentation["size"])
m = mask.decode(segmentation)
m[m > 0] = 255
polygons = mask2polygon(m)
print(polygons)