从小边界框到大边界框的转换

问题描述 投票:0回答:1

我有一个图像中大边界框的四个角的坐标,我也有一个大边界框内的较小边界框的坐标。 python代码中有什么方法可以获取从小到大的框坐标的转换信息,以便可以将此转换应用于任何框的坐标并接收其对应的较大的框坐标?也许使用openCV?

python opencv transform coordinate-transformation
1个回答
0
投票

您可以使用简单的比率,如果定义,则用左下角和右上角坐标定义框。

smallBox = ((x0, y0), (x1, y1))
bigBox = ((x2, y2), (x3, y3))
width = lambda box: box[1][0] - box[0][0]
length = lambda box: box[1][1] - box[0][1]
ratio = (width(bigBox)/width(smallBox), length(bigBox)/length(smallBox))
transform_axis = lambda axis, units: bigBox[0][axis]+(units - smallBox[0][axis])*ratio[axis]
transform = lambda x, y: (transform_axis(0, x), transform_axis(1, y))
© www.soinside.com 2019 - 2024. All rights reserved.