提交 3936c550 编写于 作者: K Kentaro Wada

Add group_id for shape annotation

上级 b3c67fec
{ {
"version": "3.14.2", "version": "3.22.0",
"flags": {}, "flags": {},
"shapes": [ "shapes": [
{ {
"label": "person-1", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
250.984126984127, 250.8142292490119,
106.92063492063491 107.33596837944665
], ],
[ [
229.984126984127, 229.8142292490119,
118.92063492063491 119.33596837944665
], ],
[ [
221.984126984127, 221.8142292490119,
134.9206349206349 135.33596837944665
], ],
[ [
223.984126984127, 223.8142292490119,
147.9206349206349 148.33596837944665
], ],
[ [
217.984126984127, 217.8142292490119,
160.9206349206349 161.33596837944665
], ],
[ [
202.984126984127, 202.8142292490119,
167.9206349206349 168.33596837944665
], ],
[ [
192.984126984127, 192.8142292490119,
199.9206349206349 200.33596837944665
], ],
[ [
194.984126984127, 194.8142292490119,
221.9206349206349 222.33596837944665
], ],
[ [
199.984126984127, 199.8142292490119,
226.9206349206349 227.33596837944665
], ],
[ [
191.984126984127, 191.8142292490119,
233.9206349206349 234.33596837944665
], ],
[ [
197.984126984127, 197.8142292490119,
263.92063492063494 264.3359683794467
], ],
[ [
213.984126984127, 213.8142292490119,
294.92063492063494 295.3359683794467
], ],
[ [
214.984126984127, 214.8142292490119,
319.92063492063494 320.3359683794467
], ],
[ [
221.984126984127, 221.8142292490119,
326.92063492063494 327.3359683794467
], ],
[ [
235.984126984127, 235.8142292490119,
325.92063492063494 326.3359683794467
], ],
[ [
240.984126984127, 240.8142292490119,
322.92063492063494 323.3359683794467
], ],
[ [
235.984126984127, 235.8142292490119,
297.92063492063494 298.3359683794467
], ],
[ [
238.984126984127, 238.8142292490119,
286.92063492063494 287.3359683794467
], ],
[ [
234.984126984127, 234.8142292490119,
267.92063492063494 268.3359683794467
], ],
[ [
257.984126984127, 257.81422924901193,
257.92063492063494 258.3359683794467
], ],
[ [
264.984126984127, 264.81422924901193,
263.92063492063494 264.3359683794467
], ],
[ [
256.984126984127, 256.81422924901193,
272.92063492063494 273.3359683794467
], ],
[ [
259.984126984127, 259.81422924901193,
281.92063492063494 282.3359683794467
], ],
[ [
284.984126984127, 284.81422924901193,
287.92063492063494 288.3359683794467
], ],
[ [
297.984126984127, 297.81422924901193,
277.92063492063494 278.3359683794467
], ],
[ [
288.984126984127, 288.81422924901193,
269.92063492063494 270.3359683794467
], ],
[ [
281.984126984127, 281.81422924901193,
269.92063492063494 270.3359683794467
], ],
[ [
283.984126984127, 283.81422924901193,
263.92063492063494 264.3359683794467
], ],
[ [
292.984126984127, 292.81422924901193,
260.92063492063494 261.3359683794467
], ],
[ [
308.984126984127, 308.81422924901193,
235.9206349206349 236.33596837944665
], ],
[ [
313.984126984127, 313.81422924901193,
216.9206349206349 217.33596837944665
], ],
[ [
309.984126984127, 309.81422924901193,
207.9206349206349 208.33596837944665
], ],
[ [
312.984126984127, 312.81422924901193,
201.9206349206349 202.33596837944665
], ],
[ [
308.984126984127, 308.81422924901193,
184.9206349206349 185.33596837944665
], ],
[ [
291.984126984127, 291.81422924901193,
172.9206349206349 173.33596837944665
], ],
[ [
269.984126984127, 269.81422924901193,
158.9206349206349 159.33596837944665
], ],
[ [
261.984126984127, 261.81422924901193,
153.9206349206349 154.33596837944665
], ],
[ [
264.984126984127, 264.81422924901193,
141.9206349206349 142.33596837944665
], ],
[ [
273.984126984127, 273.81422924901193,
136.9206349206349 137.33596837944665
], ],
[ [
278.984126984127, 278.81422924901193,
129.9206349206349 130.33596837944665
], ],
[ [
270.984126984127, 270.81422924901193,
120.92063492063491 121.33596837944665
] ]
], ],
"group_id": null,
"shape_type": "polygon", "shape_type": "polygon",
"flags": { "flags": {}
"occluded": true,
"truncated": false,
"male": true
}
}, },
{ {
"label": "person-2", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
482, 482.81422924901193,
85 85.33596837944665
], ],
[ [
468, 468.81422924901193,
90 90.33596837944665
], ],
[ [
460, 460.81422924901193,
110 110.33596837944665
], ],
[ [
460, 460.81422924901193,
127 127.33596837944665
], ],
[ [
444, 444.81422924901193,
137 137.33596837944665
], ],
[ [
419, 419.81422924901193,
153 153.33596837944665
], ],
[ [
410, 410.81422924901193,
163 163.33596837944665
], ],
[ [
403, 403.81422924901193,
168 168.33596837944665
], ],
[ [
394, 394.81422924901193,
170 170.33596837944665
], ],
[ [
386, 386.81422924901193,
168 168.33596837944665
], ],
[ [
386, 386.81422924901193,
184 184.33596837944665
], ],
[ [
392, 392.81422924901193,
182 182.33596837944665
], ],
[ [
410, 410.81422924901193,
187 187.33596837944665
], ],
[ [
414, 414.81422924901193,
192 192.33596837944665
], ],
[ [
437, 437.81422924901193,
189 189.33596837944665
], ],
[ [
434, 434.81422924901193,
204 204.33596837944665
], ],
[ [
390, 390.81422924901193,
195 195.33596837944665
], ],
[ [
386, 386.81422924901193,
195 195.33596837944665
], ],
[ [
387, 387.81422924901193,
208 208.33596837944665
], ],
[ [
381, 381.81422924901193,
212 212.33596837944665
], ],
[ [
372, 372.81422924901193,
212 212.33596837944665
], ],
[ [
372, 372.81422924901193,
216 216.33596837944665
], ],
[ [
400, 400.81422924901193,
270 270.3359683794467
], ],
[ [
389, 389.81422924901193,
272 272.3359683794467
], ],
[ [
389, 389.81422924901193,
274 274.3359683794467
], ],
[ [
403, 403.81422924901193,
282 282.3359683794467
], ],
[ [
444, 444.81422924901193,
283 283.3359683794467
], ],
[ [
443, 443.81422924901193,
259 259.3359683794467
], ],
[ [
426, 426.81422924901193,
244 244.33596837944665
], ],
[ [
462, 462.81422924901193,
256 256.3359683794467
], ],
[ [
474, 474.81422924901193,
270 270.3359683794467
], ],
[ [
477, 477.81422924901193,
280 280.3359683794467
], ],
[ [
473, 473.81422924901193,
289 289.3359683794467
], ],
[ [
471, 471.81422924901193,
296 296.3359683794467
], ],
[ [
472, 472.81422924901193,
317 317.3359683794467
], ],
[ [
480, 480.81422924901193,
332 332.3359683794467
], ],
[ [
494, 494.81422924901193,
335 335.3359683794467
], ],
[ [
498, 498.81422924901193,
329 329.3359683794467
], ],
[ [
494, 494.81422924901193,
308 308.3359683794467
], ],
[ [
499, 499.81422924901193,
297 297.3359683794467
], ],
[ [
499, 499.81422924901193,
90 90.33596837944665
] ]
], ],
"group_id": 0,
"shape_type": "polygon", "shape_type": "polygon",
"flags": { "flags": {}
"occluded": true,
"truncated": true,
"male": true
}
}, },
{ {
"label": "bottle", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
374, 370.81422924901193,
159 170.33596837944665
], ],
[ [
369, 366.81422924901193,
170 173.33596837944665
], ],
[ [
369, 365.81422924901193,
210 182.33596837944665
], ],
[ [
375, 368.81422924901193,
212 185.33596837944665
], ]
],
"group_id": 0,
"shape_type": "polygon",
"flags": {}
},
{
"label": "bottle",
"points": [
[ [
387, 374.81422924901193,
209 159.33596837944665
], ],
[ [
385, 369.81422924901193,
185 170.33596837944665
], ],
[ [
385, 369.81422924901193,
168 210.33596837944665
], ],
[ [
385, 375.81422924901193,
165 212.33596837944665
], ],
[ [
382, 387.81422924901193,
159 209.33596837944665
] ],
],
"shape_type": "polygon",
"flags": {
"occluded": false,
"truncated": false
}
},
{
"label": "person-2",
"line_color": null,
"fill_color": null,
"points": [
[ [
370, 385.81422924901193,
170 185.33596837944665
], ],
[ [
366, 385.81422924901193,
173 168.33596837944665
], ],
[ [
365, 385.81422924901193,
182 165.33596837944665
], ],
[ [
368, 382.81422924901193,
185 159.33596837944665
] ]
], ],
"group_id": null,
"shape_type": "polygon", "shape_type": "polygon",
"flags": { "flags": {}
"occluded": true,
"truncated": false,
"male": false
}
}, },
{ {
"label": "__ignore__", "label": "__ignore__",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
338, 338.81422924901193,
266 266.3359683794467
], ],
[ [
313, 313.81422924901193,
269 269.3359683794467
], ],
[ [
297, 297.81422924901193,
277 277.3359683794467
], ],
[ [
282, 282.81422924901193,
288 288.3359683794467
], ],
[ [
273, 273.81422924901193,
302 302.3359683794467
], ],
[ [
272, 272.81422924901193,
320 320.3359683794467
], ],
[ [
279, 279.81422924901193,
337 337.3359683794467
], ],
[ [
428, 428.81422924901193,
337 337.3359683794467
], ],
[ [
432, 432.81422924901193,
316 316.3359683794467
], ],
[ [
423, 423.81422924901193,
296 296.3359683794467
], ],
[ [
403, 403.81422924901193,
283 283.3359683794467
], ],
[ [
370, 370.81422924901193,
270 270.3359683794467
] ]
], ],
"group_id": null,
"shape_type": "polygon", "shape_type": "polygon",
"flags": { "flags": {}
"occluded": false,
"truncated": true
}
} }
], ],
"imagePath": "2011_000003.jpg",
"imageData": null,
"imageHeight": 338,
"imageWidth": 500,
"lineColor": [ "lineColor": [
0, 0,
255, 255,
...@@ -505,9 +486,5 @@ ...@@ -505,9 +486,5 @@
0, 0,
0, 0,
128 128
], ]
"imagePath": "2011_000003.jpg",
"imageData": null,
"imageHeight": 338,
"imageWidth": 500
} }
\ No newline at end of file
{ {
"imagePath": "2011_000006.jpg", "version": "3.22.0",
"flags": {},
"shapes": [ "shapes": [
{ {
"line_color": null, "label": "person",
"points": [ "points": [
[ [
204.936170212766, 204.936170212766,
...@@ -105,11 +106,12 @@ ...@@ -105,11 +106,12 @@
112.56382978723406 112.56382978723406
] ]
], ],
"fill_color": null, "group_id": null,
"label": "person-1" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "person",
"points": [ "points": [
[ [
271.936170212766, 271.936170212766,
...@@ -188,11 +190,12 @@ ...@@ -188,11 +190,12 @@
148.56382978723406 148.56382978723406
] ]
], ],
"fill_color": null, "group_id": null,
"label": "person-2" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "person",
"points": [ "points": [
[ [
308.936170212766, 308.936170212766,
...@@ -259,11 +262,12 @@ ...@@ -259,11 +262,12 @@
115.56382978723406 115.56382978723406
] ]
], ],
"fill_color": null, "group_id": null,
"label": "person-3" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "chair",
"points": [ "points": [
[ [
308.936170212766, 308.936170212766,
...@@ -326,11 +330,12 @@ ...@@ -326,11 +330,12 @@
241.56382978723406 241.56382978723406
] ]
], ],
"fill_color": null, "group_id": null,
"label": "chair" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "person",
"points": [ "points": [
[ [
425.936170212766, 425.936170212766,
...@@ -357,11 +362,12 @@ ...@@ -357,11 +362,12 @@
91.56382978723406 91.56382978723406
] ]
], ],
"fill_color": null, "group_id": null,
"label": "person-4" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "__ignore__",
"points": [ "points": [
[ [
457.936170212766, 457.936170212766,
...@@ -380,11 +386,12 @@ ...@@ -380,11 +386,12 @@
87.56382978723406 87.56382978723406
] ]
], ],
"fill_color": null, "group_id": null,
"label": "__ignore__" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "sofa",
"points": [ "points": [
[ [
183.936170212766, 183.936170212766,
...@@ -423,11 +430,12 @@ ...@@ -423,11 +430,12 @@
203.56382978723406 203.56382978723406
] ]
], ],
"fill_color": null, "group_id": 0,
"label": "sofa" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "sofa",
"points": [ "points": [
[ [
103.93617021276599, 103.93617021276599,
...@@ -442,11 +450,12 @@ ...@@ -442,11 +450,12 @@
311.56382978723406 311.56382978723406
] ]
], ],
"fill_color": null, "group_id": 0,
"label": "sofa" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "sofa",
"points": [ "points": [
[ [
348.936170212766, 348.936170212766,
...@@ -485,11 +494,12 @@ ...@@ -485,11 +494,12 @@
164.56382978723406 164.56382978723406
] ]
], ],
"fill_color": null, "group_id": 0,
"label": "sofa" "shape_type": "polygon",
"flags": {}
}, },
{ {
"line_color": null, "label": "sofa",
"points": [ "points": [
[ [
246.936170212766, 246.936170212766,
...@@ -508,11 +518,15 @@ ...@@ -508,11 +518,15 @@
256.56382978723406 256.56382978723406
] ]
], ],
"fill_color": null, "group_id": 0,
"label": "sofa" "shape_type": "polygon",
"flags": {}
} }
], ],
"imagePath": "2011_000006.jpg",
"imageData": null, "imageData": null,
"imageHeight": 375,
"imageWidth": 500,
"lineColor": [ "lineColor": [
0, 0,
255, 255,
......
{ {
"version": "3.22.0",
"flags": {},
"shapes": [ "shapes": [
{ {
"label": "person", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
250.8142292490119, 250.8142292490119,
...@@ -169,12 +169,13 @@ ...@@ -169,12 +169,13 @@
270.81422924901193, 270.81422924901193,
121.33596837944665 121.33596837944665
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "person", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
482.81422924901193, 482.81422924901193,
...@@ -340,12 +341,37 @@ ...@@ -340,12 +341,37 @@
499.81422924901193, 499.81422924901193,
90.33596837944665 90.33596837944665
] ]
] ],
"group_id": 0,
"shape_type": "polygon",
"flags": {}
},
{
"label": "person",
"points": [
[
370.81422924901193,
170.33596837944665
],
[
366.81422924901193,
173.33596837944665
],
[
365.81422924901193,
182.33596837944665
],
[
368.81422924901193,
185.33596837944665
]
],
"group_id": 0,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "bottle", "label": "bottle",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
374.81422924901193, 374.81422924901193,
...@@ -383,35 +409,13 @@ ...@@ -383,35 +409,13 @@
382.81422924901193, 382.81422924901193,
159.33596837944665 159.33596837944665
] ]
] ],
}, "group_id": null,
{ "shape_type": "polygon",
"label": "person", "flags": {}
"line_color": null,
"fill_color": null,
"points": [
[
370.81422924901193,
170.33596837944665
],
[
366.81422924901193,
173.33596837944665
],
[
365.81422924901193,
182.33596837944665
],
[
368.81422924901193,
185.33596837944665
]
]
}, },
{ {
"label": "__ignore__", "label": "__ignore__",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
338.81422924901193, 338.81422924901193,
...@@ -461,9 +465,16 @@ ...@@ -461,9 +465,16 @@
370.81422924901193, 370.81422924901193,
270.3359683794467 270.3359683794467
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
} }
], ],
"imagePath": "2011_000003.jpg",
"imageData": null,
"imageHeight": 338,
"imageWidth": 500,
"lineColor": [ "lineColor": [
0, 0,
255, 255,
...@@ -475,7 +486,5 @@ ...@@ -475,7 +486,5 @@
0, 0,
0, 0,
128 128
], ]
"imagePath": "2011_000003.jpg",
"imageData": null
} }
\ No newline at end of file
{ {
"version": "3.22.0",
"flags": {},
"shapes": [ "shapes": [
{ {
"label": "person", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
204.936170212766, 204.936170212766,
...@@ -105,12 +105,13 @@ ...@@ -105,12 +105,13 @@
216.936170212766, 216.936170212766,
112.56382978723406 112.56382978723406
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "person", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
271.936170212766, 271.936170212766,
...@@ -188,12 +189,13 @@ ...@@ -188,12 +189,13 @@
296.936170212766, 296.936170212766,
148.56382978723406 148.56382978723406
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "person", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
308.936170212766, 308.936170212766,
...@@ -259,12 +261,13 @@ ...@@ -259,12 +261,13 @@
336.936170212766, 336.936170212766,
115.56382978723406 115.56382978723406
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "chair", "label": "chair",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
308.936170212766, 308.936170212766,
...@@ -326,12 +329,13 @@ ...@@ -326,12 +329,13 @@
350.936170212766, 350.936170212766,
241.56382978723406 241.56382978723406
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "person", "label": "person",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
425.936170212766, 425.936170212766,
...@@ -357,12 +361,13 @@ ...@@ -357,12 +361,13 @@
446.936170212766, 446.936170212766,
91.56382978723406 91.56382978723406
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "__ignore__", "label": "__ignore__",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
457.936170212766, 457.936170212766,
...@@ -380,12 +385,13 @@ ...@@ -380,12 +385,13 @@
474.936170212766, 474.936170212766,
87.56382978723406 87.56382978723406
] ]
] ],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "sofa", "label": "sofa",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
183.936170212766, 183.936170212766,
...@@ -423,12 +429,13 @@ ...@@ -423,12 +429,13 @@
110.93617021276599, 110.93617021276599,
203.56382978723406 203.56382978723406
] ]
] ],
"group_id": 0,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "sofa", "label": "sofa",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
103.93617021276599, 103.93617021276599,
...@@ -442,12 +449,13 @@ ...@@ -442,12 +449,13 @@
97.93617021276599, 97.93617021276599,
311.56382978723406 311.56382978723406
] ]
] ],
"group_id": 0,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "sofa", "label": "sofa",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
348.936170212766, 348.936170212766,
...@@ -485,12 +493,13 @@ ...@@ -485,12 +493,13 @@
353.936170212766, 353.936170212766,
164.56382978723406 164.56382978723406
] ]
] ],
"group_id": 0,
"shape_type": "polygon",
"flags": {}
}, },
{ {
"label": "sofa", "label": "sofa",
"line_color": null,
"fill_color": null,
"points": [ "points": [
[ [
246.936170212766, 246.936170212766,
...@@ -508,9 +517,16 @@ ...@@ -508,9 +517,16 @@
261.936170212766, 261.936170212766,
256.56382978723406 256.56382978723406
] ]
] ],
"group_id": 0,
"shape_type": "polygon",
"flags": {}
} }
], ],
"imagePath": "2011_000006.jpg",
"imageData": null,
"imageHeight": 375,
"imageWidth": 500,
"lineColor": [ "lineColor": [
0, 0,
255, 255,
...@@ -522,7 +538,5 @@ ...@@ -522,7 +538,5 @@
0, 0,
0, 0,
128 128
], ]
"imagePath": "2011_000006.jpg",
"imageData": null
} }
\ No newline at end of file
...@@ -895,7 +895,9 @@ class MainWindow(QtWidgets.QMainWindow): ...@@ -895,7 +895,9 @@ class MainWindow(QtWidgets.QMainWindow):
shape = self.labelList.get_shape_from_item(item) shape = self.labelList.get_shape_from_item(item)
if shape is None: if shape is None:
return return
text, flags = self.labelDialog.popUp(shape.label, flags=shape.flags) text, flags, group_id = self.labelDialog.popUp(
text=shape.label, flags=shape.flags, group_id=shape.group_id,
)
if text is None: if text is None:
return return
if not self.validateLabel(text): if not self.validateLabel(text):
...@@ -908,10 +910,14 @@ class MainWindow(QtWidgets.QMainWindow): ...@@ -908,10 +910,14 @@ class MainWindow(QtWidgets.QMainWindow):
return return
shape.label = text shape.label = text
shape.flags = flags shape.flags = flags
item.setText(text) shape.group_id = group_id
if shape.group_id is None:
item.setText(shape.label)
else:
item.setText('{} ({})'.format(shape.label, shape.group_id))
self.setDirty() self.setDirty()
if not self.uniqLabelList.findItems(text, Qt.MatchExactly): if not self.uniqLabelList.findItems(shape.label, Qt.MatchExactly):
self.uniqLabelList.addItem(text) self.uniqLabelList.addItem(shape.label)
self.uniqLabelList.sortItems() self.uniqLabelList.sortItems()
def fileSearchChanged(self): def fileSearchChanged(self):
...@@ -955,7 +961,11 @@ class MainWindow(QtWidgets.QMainWindow): ...@@ -955,7 +961,11 @@ class MainWindow(QtWidgets.QMainWindow):
self.actions.edit.setEnabled(n_selected == 1) self.actions.edit.setEnabled(n_selected == 1)
def addLabel(self, shape): def addLabel(self, shape):
item = QtWidgets.QListWidgetItem(shape.label) if shape.group_id is None:
text = shape.label
else:
text = '{} ({})'.format(shape.label, shape.group_id)
item = QtWidgets.QListWidgetItem(text)
item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
item.setCheckState(Qt.Checked) item.setCheckState(Qt.Checked)
self.labelList.itemsToShapes.append((item, shape)) self.labelList.itemsToShapes.append((item, shape))
...@@ -963,7 +973,7 @@ class MainWindow(QtWidgets.QMainWindow): ...@@ -963,7 +973,7 @@ class MainWindow(QtWidgets.QMainWindow):
if not self.uniqLabelList.findItems(shape.label, Qt.MatchExactly): if not self.uniqLabelList.findItems(shape.label, Qt.MatchExactly):
self.uniqLabelList.addItem(shape.label) self.uniqLabelList.addItem(shape.label)
self.uniqLabelList.sortItems() self.uniqLabelList.sortItems()
self.labelDialog.addLabelHistory(item.text()) self.labelDialog.addLabelHistory(shape.label)
for action in self.actions.onShapesPresent: for action in self.actions.onShapesPresent:
action.setEnabled(True) action.setEnabled(True)
...@@ -987,8 +997,11 @@ class MainWindow(QtWidgets.QMainWindow): ...@@ -987,8 +997,11 @@ class MainWindow(QtWidgets.QMainWindow):
points = shape['points'] points = shape['points']
shape_type = shape['shape_type'] shape_type = shape['shape_type']
flags = shape['flags'] flags = shape['flags']
group_id = shape.get('group_id')
shape = Shape(label=label, shape_type=shape_type) shape = Shape(
label=label, shape_type=shape_type, group_id=group_id
)
for x, y in points: for x, y in points:
shape.addPoint(QtCore.QPointF(x, y)) shape.addPoint(QtCore.QPointF(x, y))
shape.close() shape.close()
...@@ -1020,6 +1033,7 @@ class MainWindow(QtWidgets.QMainWindow): ...@@ -1020,6 +1033,7 @@ class MainWindow(QtWidgets.QMainWindow):
return dict( return dict(
label=s.label.encode('utf-8') if PY2 else s.label, label=s.label.encode('utf-8') if PY2 else s.label,
points=[(p.x(), p.y()) for p in s.points], points=[(p.x(), p.y()) for p in s.points],
group_id=s.group_id,
shape_type=s.shape_type, shape_type=s.shape_type,
flags=s.flags flags=s.flags
) )
...@@ -1127,7 +1141,8 @@ class MainWindow(QtWidgets.QMainWindow): ...@@ -1127,7 +1141,8 @@ class MainWindow(QtWidgets.QMainWindow):
text = '' text = ''
if text: if text:
self.labelList.clearSelection() self.labelList.clearSelection()
self.addLabel(self.canvas.setLastLabel(text, flags)) shape = self.canvas.setLastLabel(text, flags)
self.addLabel(shape)
self.actions.editMode.setEnabled(True) self.actions.editMode.setEnabled(True)
self.actions.undoLastPoint.setEnabled(False) self.actions.undoLastPoint.setEnabled(False)
self.actions.undo.setEnabled(True) self.actions.undo.setEnabled(True)
......
...@@ -88,6 +88,7 @@ class LabelFile(object): ...@@ -88,6 +88,7 @@ class LabelFile(object):
points=s['points'], points=s['points'],
shape_type=s.get('shape_type', 'polygon'), shape_type=s.get('shape_type', 'polygon'),
flags=s.get('flags', {}), flags=s.get('flags', {}),
group_id=s.get('group_id')
) )
for s in data['shapes'] for s in data['shapes']
] ]
......
...@@ -37,8 +37,9 @@ class Shape(object): ...@@ -37,8 +37,9 @@ class Shape(object):
scale = 1.0 scale = 1.0
def __init__(self, label=None, line_color=None, shape_type=None, def __init__(self, label=None, line_color=None, shape_type=None,
flags=None): flags=None, group_id=None):
self.label = label self.label = label
self.group_id = group_id
self.points = [] self.points = []
self.fill = False self.fill = False
self.selected = False self.selected = False
......
...@@ -43,9 +43,17 @@ class LabelDialog(QtWidgets.QDialog): ...@@ -43,9 +43,17 @@ class LabelDialog(QtWidgets.QDialog):
self.edit.editingFinished.connect(self.postProcess) self.edit.editingFinished.connect(self.postProcess)
if flags: if flags:
self.edit.textChanged.connect(self.updateFlags) self.edit.textChanged.connect(self.updateFlags)
self.edit_group_id = QtWidgets.QLineEdit()
self.edit_group_id.setPlaceholderText('Group ID')
self.edit_group_id.setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp(r'\d*'), None)
)
layout = QtWidgets.QVBoxLayout() layout = QtWidgets.QVBoxLayout()
if show_text_field: if show_text_field:
layout.addWidget(self.edit) layout_edit = QtWidgets.QHBoxLayout()
layout_edit.addWidget(self.edit, 6)
layout_edit.addWidget(self.edit_group_id, 2)
layout.addLayout(layout_edit)
# buttons # buttons
self.buttonBox = bb = QtWidgets.QDialogButtonBox( self.buttonBox = bb = QtWidgets.QDialogButtonBox(
QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel, QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel,
...@@ -178,7 +186,13 @@ class LabelDialog(QtWidgets.QDialog): ...@@ -178,7 +186,13 @@ class LabelDialog(QtWidgets.QDialog):
flags[item.text()] = item.isChecked() flags[item.text()] = item.isChecked()
return flags return flags
def popUp(self, text=None, move=True, flags=None): def getGroupId(self):
group_id = self.edit_group_id.text()
if group_id:
return int(group_id)
return None
def popUp(self, text=None, move=True, flags=None, group_id=None):
if self._fit_to_content['row']: if self._fit_to_content['row']:
self.labelList.setMinimumHeight( self.labelList.setMinimumHeight(
self.labelList.sizeHintForRow(0) * self.labelList.count() + 2 self.labelList.sizeHintForRow(0) * self.labelList.count() + 2
...@@ -196,6 +210,10 @@ class LabelDialog(QtWidgets.QDialog): ...@@ -196,6 +210,10 @@ class LabelDialog(QtWidgets.QDialog):
self.resetFlags(text) self.resetFlags(text)
self.edit.setText(text) self.edit.setText(text)
self.edit.setSelection(0, len(text)) self.edit.setSelection(0, len(text))
if group_id is None:
self.edit_group_id.clear()
else:
self.edit_group_id.setText(str(group_id))
items = self.labelList.findItems(text, QtCore.Qt.MatchFixedString) items = self.labelList.findItems(text, QtCore.Qt.MatchFixedString)
if items: if items:
if len(items) != 1: if len(items) != 1:
...@@ -207,6 +225,6 @@ class LabelDialog(QtWidgets.QDialog): ...@@ -207,6 +225,6 @@ class LabelDialog(QtWidgets.QDialog):
if move: if move:
self.move(QtGui.QCursor.pos()) self.move(QtGui.QCursor.pos())
if self.exec_(): if self.exec_():
return self.edit.text(), self.getFlags() return self.edit.text(), self.getFlags(), self.getGroupId()
else: else:
return None, None return None, None, None
...@@ -59,9 +59,10 @@ def test_LabelDialog_popUp(qtbot): ...@@ -59,9 +59,10 @@ def test_LabelDialog_popUp(qtbot):
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
QtCore.QTimer.singleShot(500, interact) QtCore.QTimer.singleShot(500, interact)
label, flags = widget.popUp('cat') label, flags, group_id = widget.popUp('cat')
assert label == 'person' assert label == 'person'
assert flags == {} assert flags == {}
assert group_id is None
# popUp() # popUp()
...@@ -70,9 +71,10 @@ def test_LabelDialog_popUp(qtbot): ...@@ -70,9 +71,10 @@ def test_LabelDialog_popUp(qtbot):
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
QtCore.QTimer.singleShot(500, interact) QtCore.QTimer.singleShot(500, interact)
label, flags = widget.popUp() label, flags, group_id = widget.popUp()
assert label == 'person' assert label == 'person'
assert flags == {} assert flags == {}
assert group_id is None
# popUp() + key_Up # popUp() + key_Up
...@@ -82,6 +84,7 @@ def test_LabelDialog_popUp(qtbot): ...@@ -82,6 +84,7 @@ def test_LabelDialog_popUp(qtbot):
qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA qtbot.keyClick(widget.edit, QtCore.Qt.Key_Enter) # NOQA
QtCore.QTimer.singleShot(500, interact) QtCore.QTimer.singleShot(500, interact)
label, flags = widget.popUp() label, flags, group_id = widget.popUp()
assert label == 'dog' assert label == 'dog'
assert flags == {} assert flags == {}
assert group_id is None
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册