maskrcnn_benchmark/structures/bounding_box.py
def transpose(self, method, angle = None):
        """
        Transpose bounding box (flip or rotate in 90 degree steps)
        :param method: One of :py:attr:`PIL.Image.FLIP_LEFT_RIGHT`,
          :py:attr:`PIL.Image.FLIP_TOP_BOTTOM`, :py:attr:`PIL.Image.ROTATE_90`,
          :py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270`,
          :py:attr:`PIL.Image.TRANSPOSE` or :py:attr:`PIL.Image.TRANSVERSE`.
        """
        # if method not in (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM):
        #     raise NotImplementedError(
        #         "Only FLIP_LEFT_RIGHT and FLIP_TOP_BOTTOM implemented"
        #     )

        image_width, image_height = self.size
        xmin, ymin, xmax, ymax = self._split_into_xyxy()
        if method == FLIP_LEFT_RIGHT:
            TO_REMOVE = 1
            transposed_xmin = image_width - xmax - TO_REMOVE
            transposed_xmax = image_width - xmin - TO_REMOVE
            transposed_ymin = ymin
            transposed_ymax = ymax
        elif method == FLIP_TOP_BOTTOM:
            transposed_xmin = xmin
            transposed_xmax = xmax
            transposed_ymin = image_height - ymax
            transposed_ymax = image_height - ymin
#         elif method == ROTATE:
#             if angle is not None:
#                 print(angle)
#                 if angle == 90:
#                     h_mid = image_height // 2
#                     w_mid = image_width // 2
#                     M = cv2.getRotationMatrix2D((h_mid, w_mid),90,1)
#                     corners = np.hstack((xmin,ymin,xmax,ymax,xmin,ymax,xmax,ymin))
#                     corners = corners.reshape(-1,2)
#                     corners = np.hstack((corners, np.ones((corners.shape[0],1), dtype = type(corners[0][0]))))
        
#                     calculated = np.dot(M,corners.T).T   
#                     calculated = calculated.reshape(-1,8)
# #                   print(calculated.shape)
#                     x_ = calculated[:,[0,2,4,6]]
#                     y_ = calculated[:,[1,3,5,7]]
#                     transposed_xmin = np.min(x_,1).reshape(-1,1)
#                     transposed_xmax = np.max(x_,1).reshape(-1,1)
#                     transposed_ymin = np.min(y_,1).reshape(-1,1)
#                     transposed_ymax = np.max(y_,1).reshape(-1,1)

        transposed_boxes = torch.cat(
            (transposed_xmin, transposed_ymin, transposed_xmax, transposed_ymax), dim=-1
        )
        bbox = BoxList(transposed_boxes, self.size, mode="xyxy")
        # bbox._copy_extra_fields(self)
        for k, v in self.extra_fields.items():
            if not isinstance(v, torch.Tensor):
                v = v.transpose(method)
            bbox.add_field(k, v)
        return bbox.convert(self.mode)

        Transpose bounding box (flip or rotate in 90 degree steps)
        :param method: One of :py:attr:`PIL.Image.FLIP_LEFT_RIGHT`,
          :py:attr:`PIL.Image.FLIP_TOP_BOTTOM`, :py:attr:`PIL.Image.ROTATE_90`,
          :py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270`,
          :py:attr:`PIL.Image.TRANSPOSE` or :py:attr:`PIL.Image.TRANSVERSE`.
        
Transpose bounding box (flip or rotate in 90 degree steps)
Transpose bounding box ( flip or rotate in 90 degree steps )
def transpose(self, method, angle = None):
        image_width, image_height = self.size
        xmin, ymin, xmax, ymax = self._split_into_xyxy()
        if method == FLIP_LEFT_RIGHT:
            TO_REMOVE = 1
            transposed_xmin = image_width - xmax - TO_REMOVE
            transposed_xmax = image_width - xmin - TO_REMOVE
            transposed_ymin = ymin
            transposed_ymax = ymax
        elif method == FLIP_TOP_BOTTOM:
            transposed_xmin = xmin
            transposed_xmax = xmax
            transposed_ymin = image_height - ymax
            transposed_ymax = image_height - ymin
        transposed_boxes = torch.cat(
            (transposed_xmin, transposed_ymin, transposed_xmax, transposed_ymax), dim=-1
        )
        bbox = BoxList(transposed_boxes, self.size, mode="xyxy")
        for k, v in self.extra_fields.items():
            if not isinstance(v, torch.Tensor):
                v = v.transpose(method)
            bbox.add_field(k, v)
        return bbox.convert(self.mode)
def transpose ( self , method , angle = None ) : image_width , image_height = self . size xmin , ymin , xmax , ymax = self . _split_into_xyxy ( ) if method == FLIP_LEFT_RIGHT : TO_REMOVE = 1 transposed_xmin = image_width - xmax - TO_REMOVE transposed_xmax = image_width - xmin - TO_REMOVE transposed_ymin = ymin transposed_ymax = ymax elif method == FLIP_TOP_BOTTOM : transposed_xmin = xmin transposed_xmax = xmax transposed_ymin = image_height - ymax transposed_ymax = image_height - ymin transposed_boxes = torch . cat ( ( transposed_xmin , transposed_ymin , transposed_xmax , transposed_ymax ) , dim = - 1 ) bbox = BoxList ( transposed_boxes , self . size , mode = "xyxy" ) for k , v in self . extra_fields . items ( ) : if not isinstance ( v , torch . Tensor ) : v = v . transpose ( method ) bbox . add_field ( k , v ) return bbox . convert ( self . mode )
Transpose bounding box (flip or rotate in 90 degree steps)
Transpose bounding box ( flip or rotate in 90 degree steps )
"""
        Transpose bounding box (flip or rotate in 90 degree steps)
        :param method: One of :py:attr:`PIL.Image.FLIP_LEFT_RIGHT`,
          :py:attr:`PIL.Image.FLIP_TOP_BOTTOM`, :py:attr:`PIL.Image.ROTATE_90`,
          :py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270`,
          :py:attr:`PIL.Image.TRANSPOSE` or :py:attr:`PIL.Image.TRANSVERSE`.
        """ # if method not in (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM): #     raise NotImplementedError( #         "Only FLIP_LEFT_RIGHT and FLIP_TOP_BOTTOM implemented" #     ) #         elif method == ROTATE: #             if angle is not None: #                 print(angle) #                 if angle == 90: #                     h_mid = image_height // 2 #                     w_mid = image_width // 2 #                     M = cv2.getRotationMatrix2D((h_mid, w_mid),90,1) #                     corners = np.hstack((xmin,ymin,xmax,ymax,xmin,ymax,xmax,ymin)) #                     corners = corners.reshape(-1,2) #                     corners = np.hstack((corners, np.ones((corners.shape[0],1), dtype = type(corners[0][0])))) #                     calculated = np.dot(M,corners.T).T    #                     calculated = calculated.reshape(-1,8) # #                   print(calculated.shape) #                     x_ = calculated[:,[0,2,4,6]] #                     y_ = calculated[:,[1,3,5,7]] #                     transposed_xmin = np.min(x_,1).reshape(-1,1) #                     transposed_xmax = np.max(x_,1).reshape(-1,1) #                     transposed_ymin = np.min(y_,1).reshape(-1,1) #                     transposed_ymax = np.max(y_,1).reshape(-1,1) # bbox._copy_extra_fields(self)
self
method
One of :py:attr:`PIL.Image.FLIP_LEFT_RIGHT`,
:py:attr:`PIL.Image.FLIP_TOP_BOTTOM`, :py:attr:`PIL.Image.ROTATE_90`,
:py:attr:`PIL.Image.ROTATE_180`, :py:attr:`PIL.Image.ROTATE_270`,
:py:attr:`PIL.Image.TRANSPOSE` or :py:attr:`PIL.Image.TRANSVERSE`.
One of : py : attr : ` PIL . Image . FLIP_LEFT_RIGHT ` : py : attr : ` PIL . Image . FLIP_TOP_BOTTOM ` : py : attr : ` PIL . Image . ROTATE_90 ` : py : attr : ` PIL . Image . ROTATE_180 ` : py : attr : ` PIL . Image . ROTATE_270 ` : py : attr : ` PIL . Image . TRANSPOSE ` or : py : attr : ` PIL . Image . TRANSVERSE ` .
angle