Exemplo n.º 1
0
    def _get_bbox(self, image, shape):
        """获得bbox
        Args:
            image:图像 (已经读取进内存的图像)
            shape:图像标注

        Returns: bbox坐标 (x1, y1, x2, y2)
        """
        imh, imw = image.shape[:2]
        if len(shape) == 4:
            w, h = shape[2] - shape[0], shape[3] - shape[1]
        else:
            w, h = shape
        # Todo ???
        context_amount = 0.5
        exemplar_size = cfg.TRAIN.EXEMPLAR_SIZE
        wc_z = w + context_amount * (w + h)
        hc_z = h + context_amount * (w + h)
        s_z = np.sqrt(wc_z * hc_z)
        scale_z = exemplar_size / s_z
        w = w * scale_z
        h = h * scale_z
        cx, cy = imw // 2, imh // 2
        bbox = center2corner(Center(cx, cy, w, h))
        return bbox
Exemplo n.º 2
0
 def _get_bbox(self, image, shape):
     imh, imw = image.shape[:2]
     if len(shape) == 4:
         w, h = shape[2]-shape[0], shape[3]-shape[1]
     else:
         w, h = shape
     context_amount = 0.5
     exemplar_size = cfg.TRAIN.EXEMPLAR_SIZE
     wc_z = w + context_amount * (w+h)
     hc_z = h + context_amount * (w+h)
     s_z = np.sqrt(wc_z * hc_z)
     scale_z = exemplar_size / s_z
     w = w*scale_z
     h = h*scale_z
     cx, cy = imw//2, imh//2
     bbox = center2corner(Center(cx, cy, w, h))
     return bbox
Exemplo n.º 3
0
    def __call__(self, image, bbox, size, gray=False):
        shape = image.shape
        crop_bbox = center2corner(
            Center(shape[0] // 2, shape[1] // 2, size - 1, size - 1))
        # gray augmentation
        if gray:
            image = self._gray_aug(image)

        # shift scale augmentation
        image, bbox = self._shift_scale_aug(image, bbox, crop_bbox, size)

        # color augmentation
        if self.color > np.random.random():
            image = self._color_aug(image)

        # blur augmentation
        if self.blur > np.random.random():
            image = self._blur_aug(image)

        # flip augmentation
        if self.flip and self.flip > np.random.random():
            image, bbox = self._flip_aug(image, bbox)
        return image, bbox
Exemplo n.º 4
0
    def _shift_scale_aug(self, image, bbox, crop_bbox, size):
        im_h, im_w = image.shape[:2]

        # adjust crop bounding box
        crop_bbox_center = corner2center(crop_bbox)
        if self.scale:
            scale_x = (1.0 + Augmentation.random() * self.scale)
            scale_y = (1.0 + Augmentation.random() * self.scale)
            h, w = crop_bbox_center.h, crop_bbox_center.w
            scale_x = min(scale_x, float(im_w) / w)
            scale_y = min(scale_y, float(im_h) / h)
            crop_bbox_center = Center(crop_bbox_center.x, crop_bbox_center.y,
                                      crop_bbox_center.w * scale_x,
                                      crop_bbox_center.h * scale_y)

        crop_bbox = center2corner(crop_bbox_center)
        if self.shift:
            sx = Augmentation.random() * self.shift
            sy = Augmentation.random() * self.shift

            x1, y1, x2, y2 = crop_bbox

            sx = max(-x1, min(im_w - 1 - x2, sx))
            sy = max(-y1, min(im_h - 1 - y2, sy))

            crop_bbox = Corner(x1 + sx, y1 + sy, x2 + sx, y2 + sy)

        # adjust target bounding box
        x1, y1 = crop_bbox.x1, crop_bbox.y1
        bbox = Corner(bbox.x1 - x1, bbox.y1 - y1, bbox.x2 - x1, bbox.y2 - y1)

        if self.scale:
            bbox = Corner(bbox.x1 / scale_x, bbox.y1 / scale_y,
                          bbox.x2 / scale_x, bbox.y2 / scale_y)

        image = self._crop_roi(image, crop_bbox, size)
        return image, bbox