datagen.py 文件源码

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

项目:DSOD-Pytorch-Implementation 作者: Ellinier 项目源码 文件源码
def random_zoom_out(self, img, boxes):
        '''
        Randomly zoom out the image and adjust the bbox locations.

        For bbox (xmin, ymin, xmax, ymax), the zoomed out bbox is:
        coef -- zoom out coefficient
        ((1-coef)*w/2 + coef*xmin, (1-coef)*h/2 + coef*ymin,
         (1-coed)*w/2 + coef*xmax, (1-coef)*h/2 + coef*ymax)

        Args:
           img: (PIL.Image) image.
           boxes: (tensor) bbox locations, sized [#obj, 4].

        Return:
          img: (PIL.Image) randomly zoomed out image.
          boxes: (tensor) randomly zoomed out bbox locations, sized [#obj, 4].
        '''
        coef = random.uniform(0.5, 1)
        w = img.width
        h = img.height

        xmin = (1-coef)*w/2 + coef*boxes[:,0]
        xmax = (1-coef)*w/2 + coef*boxes[:,2]
        ymin = (1-coef)*h/2 + coef*boxes[:,1]
        ymax = (1-coef)*h/2 + coef*boxes[:,3]
        boxes[:,0] = xmin
        boxes[:,1] = ymin
        boxes[:,2] = xmax
        boxes[:,3] = ymax

        top = int(h/2*(1-coef)/coef)
        bottom = int(h/2*(1-coef)/coef)
        left = int(w/2*(1-coef)/coef)
        right = int(w/2*(1-coef)/coef)

        img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_REPLICATE)
        img = cv2.resize(img, (w, h))
        return img, boxes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号