Python 将边界框旋转给定角度

Python 将边界框旋转给定角度,python,azure-cognitive-services,Python,Azure Cognitive Services,我正在处理Azure计算机视觉读取API的输出。输出具有页面的边界框和角度。我需要旋转边界框中的点 示例边界框为:“边界框”:[ 2.4533, 10.6901, 2.6147, 10.6901, 2.6147, 10.8193, 2.4533, 10.8193 ],角度为180度到180度 我需要旋转边界框中的点,以便感觉类似于0度页面的输出。我的环境是python。我找到了一个解决方案: def rotate(point, origin, degrees): radians = np

我正在处理Azure计算机视觉读取API的输出。输出具有页面的边界框和角度。我需要旋转边界框中的点

示例边界框为:“边界框”:[ 2.4533, 10.6901, 2.6147, 10.6901, 2.6147, 10.8193, 2.4533, 10.8193 ],角度为180度到180度

我需要旋转边界框中的点,以便感觉类似于0度页面的输出。我的环境是python。

我找到了一个解决方案:

def rotate(point, origin, degrees):
    radians = np.deg2rad(degrees)
    x,y = point
    offset_x, offset_y = origin
    adjusted_x = (x - offset_x)
    adjusted_y = (y - offset_y)
    cos_rad = np.cos(radians)
    sin_rad = np.sin(radians)
    qx = offset_x + cos_rad * adjusted_x + sin_rad * adjusted_y
    qy = offset_y + -sin_rad * adjusted_x + cos_rad * adjusted_y
    return qx, qy
def correctAngle(analysis):
    for page in analysis["analyzeResult"]["readResults"]:
        if page["angle"] !=0:
            for line in page['lines']:
                bBox= line['boundingBox']
                for ind in range (0, 7, 2):
                    bBox[ind],bBox[ind+1]=rotate((bBox[ind],bBox[ind+1]),(0,0),page["angle"])
                line['boundingBox']=bBox
    return analysis

请展示你试过的东西