transforms.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:GulpIO 作者: TwentyBN 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号