@@ -280,14 +280,6 @@ def plot_box(
280
280
:type wh: scalar, array_like(2), optional
281
281
:param centre: centre of box, defaults to None
282
282
:type centre: array_like(2), optional
283
- :param l: left side of box, minimum x, defaults to None
284
- :type l: float, optional
285
- :param r: right side of box, minimum x, defaults to None
286
- :type r: float, optional
287
- :param b: bottom side of box, minimum y, defaults to None
288
- :type b: float, optional
289
- :param t: top side of box, maximum y, defaults to None
290
- :type t: float, optional
291
283
:param w: width of box, defaults to None
292
284
:type w: float, optional
293
285
:param h: height of box, defaults to None
@@ -309,7 +301,7 @@ def plot_box(
309
301
310
302
The box can be specified in many ways:
311
303
312
- - bounding box which is a 2x2 matrix [xmin, xmax; ymin, ymax]
304
+ - bounding box which is a 2x2 matrix [xmin, xmax, ymin, ymax]
313
305
- bounding box [xmin, xmax, ymin, ymax]
314
306
- alternative box [xmin, ymin, xmax, ymax]
315
307
- centre and width+height
@@ -337,10 +329,7 @@ def plot_box(
337
329
else :
338
330
w , h = wh
339
331
340
- # l - left side, minimum x
341
- # r - right side, maximuim x
342
- # b - bottom side, minimum y, top in an image
343
- # t - top side, maximum y, bottom in an image
332
+ # test for various 4-coordinate versions
344
333
if bbox is not None :
345
334
lb = bbox [:2 ]
346
335
w , h = bbox [2 :]
@@ -364,17 +353,34 @@ def plot_box(
364
353
rt = (ltrb [2 ], ltrb [1 ])
365
354
w , h = rt [0 ] - lb [0 ], rt [1 ] - lb [1 ]
366
355
367
- elif centre is not None :
368
- lb = ( centre [ 0 ] - w / 2 , centre [ 1 ] - h / 2 )
356
+ elif w is not None and h is not None :
357
+ # we have width & height, one corner is enough
369
358
370
- elif lt is not None :
371
- lb = (lt [0 ], lt [1 ] - h )
359
+ if centre is not None :
360
+ lb = (centre [0 ] - w / 2 , centre [1 ] - h / 2 )
372
361
373
- elif rt is not None :
374
- lb = (rt [0 ] - w , rt [1 ] - h )
362
+ elif lt is not None :
363
+ lb = (lt [0 ], lt [1 ] - h )
375
364
376
- elif rb is not None :
377
- lb = (rb [0 ] - w , rb [1 ])
365
+ elif rt is not None :
366
+ lb = (rt [0 ] - w , rt [1 ] - h )
367
+
368
+ elif rb is not None :
369
+ lb = (rb [0 ] - w , rb [1 ])
370
+
371
+ else :
372
+ # we need two opposite corners
373
+ if lb is not None and rt is not None :
374
+ w = rt [0 ] - lb [0 ]
375
+ h = rt [1 ] - lb [1 ]
376
+
377
+ elif lt is not None and rb is not None :
378
+ lb = (lt [0 ], rb [1 ])
379
+ w = rb [0 ] - lt [0 ]
380
+ h = lt [1 ] - rb [1 ]
381
+
382
+ else :
383
+ raise ValueError ('cant compute box' )
378
384
379
385
if w < 0 :
380
386
raise ValueError ("width must be positive" )
0 commit comments