|
@@ -64,10 +64,10 @@ class LocationPart(BasePart):
|
|
|
|
|
|
class BBoxPart(BasePart):
|
|
|
|
|
|
- def __init__(self, image, annotation, rescale_size=None):
|
|
|
+ def __init__(self, image, annotation, rescale_size=None, center_cropped=True):
|
|
|
super(BBoxPart, self).__init__()
|
|
|
|
|
|
- annotation = self.rescale(image, annotation, rescale_size)
|
|
|
+ annotation = self.rescale(image, annotation, rescale_size, center_cropped)
|
|
|
# here x,y are top left corner of the part
|
|
|
self._id, self.x, self.y, self.w, self.h = annotation
|
|
|
self.is_visible = True
|
|
@@ -76,14 +76,19 @@ class BBoxPart(BasePart):
|
|
|
def as_annotation(self):
|
|
|
return np.array([self._id, self.x, self.y, self.w, self.h])
|
|
|
|
|
|
- def rescale(self, image, annotation, rescale_size):
|
|
|
+ def rescale(self, image, annotation, rescale_size, center_cropped=True):
|
|
|
+
|
|
|
if rescale_size is not None and rescale_size > 0:
|
|
|
- annotation = super(BBoxPart, self).rescale(image, annotation, rescale_size)
|
|
|
- h, w, c = utils.dimensions(image)
|
|
|
- scale = np.array([w, h]) / rescale_size
|
|
|
+ from chainer_addons.utils.imgproc import _center_crop
|
|
|
+
|
|
|
+ annotation = super(BBoxPart, self).rescale(image, annotation, rescale_size, center_cropped)
|
|
|
+
|
|
|
+ # base class rescales only x and y.
|
|
|
+ # now we need to rescale the width and height.
|
|
|
+
|
|
|
wh = annotation[3:5]
|
|
|
- wh = wh * scale
|
|
|
- annotation[3:5] = wh
|
|
|
+ new_wh = utils.rescale(image, wh, rescale_size, center_cropped, no_offset=True)
|
|
|
+ annotation[3:5] = new_wh
|
|
|
|
|
|
return annotation
|
|
|
|