def __call__(self, imgs):
"""
Args:
img (numpy.array): Image to be cropped.
Returns:
numpy.array: Cropped image.
"""
sample_w = random.choice(self.sample_sizes)
sample_h = random.choice(self.sample_sizes)
h, w = imgs[0].shape[:2]
x1 = random.randint(0, w - sample_w)
y1 = random.randint(0, h - sample_h)
for idx, img in enumerate(imgs):
if self.padding > 0:
img = cv2.copyMakeBorder(img, self.padding, self.padding,
self.padding, self.padding,
cv2.BORDER_CONSTANT, value=0)
# sample crop locations if not given
# it is necessary to keep cropping same in a video
img_crop = img[y1:y1+sample_h, x1:x1+sample_w]
imgs[idx] = img_crop
return imgs
评论列表
文章目录