transforms.py 文件源码

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

项目:GulpIO 作者: TwentyBN 项目源码 文件源码
def __call__(self, img):
        """
        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 = img.shape[:2]
        x1 = random.randint(0, w - sample_w)
        y1 = random.randint(0, h - sample_h)
        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]
        return img_crop
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号