(self, data: dict)
return data
从scales中随机选择一个尺度，对图片和文本框进行缩放
        :param data: {'img':,'text_polys':,'texts':,'ignore_tags':}
        :return:
从scales中随机选择一个尺度，对图片和文本框进行缩放
        :param data: {'img':,'text_polys':,'texts':,'ignore_tags':}
        :return:
从scales中随机选择一个尺度，对图片和文本框进行缩放 : param data : { img : text_polys : texts : ignore_tags : } : return :
def __call__(self, data: dict) -> dict:
        """
        从scales中随机选择一个尺度，对图片和文本框进行缩放
        :param data: {'img':,'text_polys':,'texts':,'ignore_tags':}
        :return:
        """
        if random.random() > self.random_rate:
            return data
        im = data['img']
        text_polys = data['text_polys']

        # ---------------------- 旋转图像 ----------------------
        w = im.shape[1]
        h = im.shape[0]
        angle = np.random.uniform(self.degrees[0], self.degrees[1])

        if self.same_size:
            nw = w
            nh = h
        else:
            # 角度变弧度
            rangle = np.deg2rad(angle)
            # 计算旋转之后图像的w, h
            nw = (abs(np.sin(rangle) * h) + abs(np.cos(rangle) * w))
            nh = (abs(np.cos(rangle) * h) + abs(np.sin(rangle) * w))
        # 构造仿射矩阵
        rot_mat = cv2.getRotationMatrix2D((nw * 0.5, nh * 0.5), angle, 1)
        # 计算原图中心点到新图中心点的偏移量
        rot_move = np.dot(rot_mat, np.array([(nw - w) * 0.5, (nh - h) * 0.5, 0]))
        # 更新仿射矩阵
        rot_mat[0, 2] += rot_move[0]
        rot_mat[1, 2] += rot_move[1]
        # 仿射变换
        rot_img = cv2.warpAffine(im, rot_mat, (int(math.ceil(nw)), int(math.ceil(nh))), flags=cv2.INTER_LANCZOS4)

        # ---------------------- 矫正bbox坐标 ----------------------
        # rot_mat是最终的旋转矩阵
        # 获取原始bbox的四个中点，然后将这四个点转换到旋转后的坐标系下
        rot_text_polys = list()
        for bbox in text_polys:
            point1 = np.dot(rot_mat, np.array([bbox[0, 0], bbox[0, 1], 1]))
            point2 = np.dot(rot_mat, np.array([bbox[1, 0], bbox[1, 1], 1]))
            point3 = np.dot(rot_mat, np.array([bbox[2, 0], bbox[2, 1], 1]))
            point4 = np.dot(rot_mat, np.array([bbox[3, 0], bbox[3, 1], 1]))
            rot_text_polys.append([point1, point2, point3, point4])
        data['img'] = rot_img
        data['text_polys'] = np.array(rot_text_polys)
        return data
def __call__ ( self , data : dict ) -> dict : if random . random ( ) > self . random_rate : return data im = data [ 'img' ] text_polys = data [ 'text_polys' ] # ---------------------- 旋转图像 ---------------------- w = im . shape [ 1 ] h = im . shape [ 0 ] angle = np . random . uniform ( self . degrees [ 0 ] , self . degrees [ 1 ] ) if self . same_size : nw = w nh = h else : # 角度变弧度 rangle = np . deg2rad ( angle ) # 计算旋转之后图像的w, h nw = ( abs ( np . sin ( rangle ) * h ) + abs ( np . cos ( rangle ) * w ) ) nh = ( abs ( np . cos ( rangle ) * h ) + abs ( np . sin ( rangle ) * w ) ) # 构造仿射矩阵 rot_mat = cv2 . getRotationMatrix2D ( ( nw * 0.5 , nh * 0.5 ) , angle , 1 ) # 计算原图中心点到新图中心点的偏移量 rot_move = np . dot ( rot_mat , np . array ( [ ( nw - w ) * 0.5 , ( nh - h ) * 0.5 , 0 ] ) ) # 更新仿射矩阵 rot_mat [ 0 , 2 ] += rot_move [ 0 ] rot_mat [ 1 , 2 ] += rot_move [ 1 ] # 仿射变换 rot_img = cv2 . warpAffine ( im , rot_mat , ( int ( math . ceil ( nw ) ) , int ( math . ceil ( nh ) ) ) , flags = cv2 . INTER_LANCZOS4 ) # ---------------------- 矫正bbox坐标 ---------------------- # rot_mat是最终的旋转矩阵 # 获取原始bbox的四个中点，然后将这四个点转换到旋转后的坐标系下 rot_text_polys = list ( ) for bbox in text_polys : point1 = np . dot ( rot_mat , np . array ( [ bbox [ 0 , 0 ] , bbox [ 0 , 1 ] , 1 ] ) ) point2 = np . dot ( rot_mat , np . array ( [ bbox [ 1 , 0 ] , bbox [ 1 , 1 ] , 1 ] ) ) point3 = np . dot ( rot_mat , np . array ( [ bbox [ 2 , 0 ] , bbox [ 2 , 1 ] , 1 ] ) ) point4 = np . dot ( rot_mat , np . array ( [ bbox [ 3 , 0 ] , bbox [ 3 , 1 ] , 1 ] ) ) rot_text_polys . append ( [ point1 , point2 , point3 , point4 ] ) data [ 'img' ] = rot_img data [ 'text_polys' ] = np . array ( rot_text_polys ) return data