将边界框旋转给定角度
Posted
技术标签:
【中文标题】将边界框旋转给定角度【英文标题】:Rotate a boundingBox by a given angle 【发布时间】:2021-02-14 00:34:33 【问题描述】:我正在处理来自 Azure 计算机视觉读取 API 的输出。输出有一个boundingBox和页面的角度。我需要旋转boundingBox中的点。
一个示例boundingBox是:“boundingBox”:[ 2.4533, 10.6901, 2.6147, 10.6901, 2.6147, 10.8193, 2.4533, 10.8193 ],角度为-180到180度。
我需要旋转边界框中的点,以便感觉类似于具有 0 度的页面的输出。我的环境是 python。
【问题讨论】:
请展示您的尝试 【参考方案1】:我找到了解决办法:
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
【讨论】:
以上是关于将边界框旋转给定角度的主要内容,如果未能解决你的问题,请参考以下文章