MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / _rotate

Method _rotate

PATH/core/data/transforms/parsing_transforms.py:239–262  ·  view source on GitHub ↗
(self, img, angle, center=None, scale=1.0, border_value=0, interpolation='bilinear', auto_bound=False)

Source from the content-addressed store, hash-verified

237 return image, label
238
239 def _rotate(self, img, angle, center=None, scale=1.0, border_value=0, interpolation='bilinear', auto_bound=False):
240 if center is not None and auto_bound:
241 raise ValueError('`auto_bound` conflicts with `center`')
242 h, w = img.shape[:2]
243 if center is None:
244 center = ((w - 1) * 0.5, (h - 1) * 0.5)
245 assert isinstance(center, tuple)
246
247 matrix = cv2.getRotationMatrix2D(center, -angle, scale)
248 if auto_bound:
249 cos = np.abs(matrix[0, 0])
250 sin = np.abs(matrix[0, 1])
251 new_w = h * sin + w * cos
252 new_h = h * cos + w * sin
253 matrix[0, 2] += (new_w - w) * 0.5
254 matrix[1, 2] += (new_h - h) * 0.5
255 w = int(np.round(new_w))
256 h = int(np.round(new_h))
257 rotated = cv2.warpAffine(
258 img,
259 matrix, (w, h),
260 flags=self.cv2_interp_codes[interpolation],
261 borderValue=border_value)
262 return rotated
263
264 def __repr__(self):
265 repr_str = self.__class__.__name__

Callers 1

__call__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected