def get_transform(self, img): h, w = img.shape[:2] do = self._rand_range() < self.prob if do: if self.horizontal: return HFlipTransform(w) elif self.vertical: return VFlipTransform(h) else: return NoOpTransform()
def get_transform(self, img): h, w = img.shape[:2] # do = self._rand_range() < self.prob # original implementation do = False # No flip! if do: if self.horizontal: return HFlipTransform(w) elif self.vertical: return VFlipTransform(h) else: return NoOpTransform()
def get_transform(self, img): h, w = img.shape[:2] do = self.do[self.idx] # print('idx', self.idx) # print('do', do) # print('self.do', self.do) self.idx += 1 if self.idx == self.ring: self.idx = 0 self.do = [self._rand_range() < self.prob] * self.ring if do: if self.horizontal: # print('HFlipTransform') return HFlipTransform(w) # print([HFlipTransform(w)]*self.ring) # yield from [HFlipTransform(w)]*self.ring elif self.vertical: return VFlipTransform(h) else: # print('NoOpTransform') return NoOpTransform()
def get_transform(self, img): h, w = img.shape[:2] if self.horizontal: return HFlipTransform(w) elif self.vertical: return VFlipTransform(h)
def Resize_rotated_box(transform, rotated_boxes): """ Apply the resizing transform on rotated boxes. For details of how these (approximation) formulas are derived, please refer to :meth:`RotatedBoxes.scale`. Args: rotated_boxes (ndarray): Nx5 floating point array of (x_center, y_center, width, height, angle_degrees) format in absolute coordinates. """ rotated_boxes = np.asarray(rotated_boxes).reshape(-1, 5) scale_factor_x = transform.new_w * 1.0 / transform.w scale_factor_y = transform.new_h * 1.0 / transform.h rotated_boxes[:, 0] *= scale_factor_x rotated_boxes[:, 1] *= scale_factor_y theta = rotated_boxes[:, 4] * np.pi / 180.0 c = np.cos(theta) s = np.sin(theta) rotated_boxes[:, 2] *= np.sqrt(np.square(scale_factor_x * c) + np.square(scale_factor_y * s)) rotated_boxes[:, 3] *= np.sqrt(np.square(scale_factor_x * s) + np.square(scale_factor_y * c)) rotated_boxes[:, 4] = np.arctan2(scale_factor_x * s, scale_factor_y * c) * 180 / np.pi return rotated_boxes HFlipTransform.register_type("rotated_box", HFlip_rotated_box) VFlipTransform.register_type("rotated_box", VFlip_rotated_box) # NoOpTransform.register_type("rotated_box", lambda t, x: x) NoOpTransform.register_type("rotated_box", NoOp_rotated_box) ResizeTransform.register_type("rotated_box", Resize_rotated_box)