parameters: (self, imgs, degrees: numbers.Number or list or tuple or np.ndarray,
                                 same_size=False)
return_statement: return imgs
docstring: 从给定的角度中选择一个角度，对图片和文本框进行旋转
          :param imgs: 原图 和 label
          :param degrees: 角度，可以是一个数值或者list
          :param same_size: 是否保持和原图一样大
          :return: 旋转后的图片和角度
docstring_summary: 从给定的角度中选择一个角度，对图片和文本框进行旋转
          :param imgs: 原图 和 label
          :param degrees: 角度，可以是一个数值或者list
          :param same_size: 是否保持和原图一样大
          :return: 旋转后的图片和角度
docstring_tokens: 从给定的角度中选择一个角度，对图片和文本框进行旋转 : param imgs : 原图 和 label : param degrees : 角度，可以是一个数值或者list : param same_size : 是否保持和原图一样大 : return : 旋转后的图片和角度
function: def random_rotate_img_bbox(self, imgs, degrees: numbers.Number or list or tuple or np.ndarray,
                                 same_size=False):
          """
          从给定的角度中选择一个角度，对图片和文本框进行旋转
          :param imgs: 原图 和 label
          :param degrees: 角度，可以是一个数值或者list
          :param same_size: 是否保持和原图一样大
          :return: 旋转后的图片和角度
          """
          if isinstance(degrees, numbers.Number):
              if degrees < 0:
                  raise ValueError("If degrees is a single number, it must be positive.")
              degrees = (-degrees, degrees)
          elif isinstance(degrees, list) or isinstance(degrees, tuple) or isinstance(degrees, np.ndarray):
              if len(degrees) != 2:
                  raise ValueError("If degrees is a sequence, it must be of len 2.")
              degrees = degrees
          else:
              raise Exception('degrees must in Number or list or tuple or np.ndarray')
          # ---------------------- 旋转图像 ----------------------
          w = imgs[0].shape[1]
          h = imgs[0].shape[0]
          angle = np.random.uniform(degrees[0], degrees[1])
  
          if 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]
          for idx in range(len(imgs)):
              # 仿射变换
              imgs[idx] = cv2.warpAffine(imgs[idx], rot_mat, (int(math.ceil(nw)), int(math.ceil(nh))), flags=cv2.INTER_LANCZOS4)
          return imgs
function_tokens: def random_rotate_img_bbox ( self , imgs , degrees : numbers . Number or list or tuple or np . ndarray , same_size = False ) : if isinstance ( degrees , numbers . Number ) : if degrees < 0 : raise ValueError ( "If degrees is a single number, it must be positive." ) degrees = ( - degrees , degrees ) elif isinstance ( degrees , list ) or isinstance ( degrees , tuple ) or isinstance ( degrees , np . ndarray ) : if len ( degrees ) != 2 : raise ValueError ( "If degrees is a sequence, it must be of len 2." ) degrees = degrees else : raise Exception ( 'degrees must in Number or list or tuple or np.ndarray' ) # ---------------------- 旋转图像 ---------------------- w = imgs [ 0 ] . shape [ 1 ] h = imgs [ 0 ] . shape [ 0 ] angle = np . random . uniform ( degrees [ 0 ] , degrees [ 1 ] ) if 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 ] for idx in range ( len ( imgs ) ) : # 仿射变换 imgs [ idx ] = cv2 . warpAffine ( imgs [ idx ] , rot_mat , ( int ( math . ceil ( nw ) ) , int ( math . ceil ( nh ) ) ) , flags = cv2 . INTER_LANCZOS4 ) return imgs