@@ -1542,7 +1542,7 @@ def obj_box_coord_scale_to_pixelunit(coord, shape=(100, 100, 3)):
15421542# exit()
15431543
15441544def obj_box_coord_centroid_to_upleft_butright (coord , to_int = False ):
1545- """ Convert one coordinate [x_center, y_center, w, h] to [x, y , x2, y2] in up-left and botton-right format.
1545+ """ Convert one coordinate [x_center, y_center, w, h] to [x1, y1 , x2, y2] in up-left and botton-right format.
15461546
15471547 Examples
15481548 ---------
@@ -1551,8 +1551,8 @@ def obj_box_coord_centroid_to_upleft_butright(coord, to_int=False):
15511551 """
15521552 assert len (coord ) == 4 , "coordinate should be 4 values : [x, y, w, h]"
15531553 x_center , y_center , w , h = coord
1554- x = x_center - w / 2
1555- y = y_center - h / 2
1554+ x = x_center - w / 2.
1555+ y = y_center - h / 2.
15561556 x2 = x + w
15571557 y2 = y + h
15581558 if to_int :
@@ -1564,14 +1564,27 @@ def obj_box_coord_centroid_to_upleft_butright(coord, to_int=False):
15641564# print(coord) [20, 30, 40, 50]
15651565# exit()
15661566
1567+ def obj_box_coord_upleft_butright_to_centroid (coord ):
1568+ """ Convert one coordinate [x1, y1, x2, y2] to [x_center, y_center, w, h].
1569+ It is the reverse process of ``obj_box_coord_centroid_to_upleft_butright``.
1570+ """
1571+ assert len (coord ) == 4 , "coordinate should be 4 values : [x1, y1, x2, y2]"
1572+ x1 , y1 , x2 , y2 = coord
1573+ w = x2 - x1
1574+ h = y2 - y1
1575+ x_c = x1 + w / 2.
1576+ y_c = y1 + h / 2.
1577+ return [x_c , y_c , w , h ]
1578+
1579+
15671580def obj_box_coord_centroid_to_upleft (coord ):
15681581 """ Convert one coordinate [x_center, y_center, w, h] to [x, y, w, h].
15691582 It is the reverse process of ``obj_box_coord_upleft_to_centroid``.
15701583 """
15711584 assert len (coord ) == 4 , "coordinate should be 4 values : [x, y, w, h]"
15721585 x_center , y_center , w , h = coord
1573- x = x_center - w / 2
1574- y = y_center - h / 2
1586+ x = x_center - w / 2.
1587+ y = y_center - h / 2.
15751588 return [x , y , w , h ]
15761589
15771590def obj_box_coord_upleft_to_centroid (coord ):
@@ -1580,8 +1593,8 @@ def obj_box_coord_upleft_to_centroid(coord):
15801593 """
15811594 assert len (coord ) == 4 , "coordinate should be 4 values : [x, y, w, h]"
15821595 x , y , w , h = coord
1583- x_center = x + w / 2
1584- y_center = y + h / 2
1596+ x_center = x + w / 2.
1597+ y_center = y + h / 2.
15851598 return [x_center , y_center , w , h ]
15861599
15871600##
0 commit comments