赞
踩
由于在遥感目标检测中经常会涉及到任意方向矩形的五个参数转换成水平外接矩形四个参数或者四个顶点的八个坐标参数;这些转换虽然并不难,但是如果身边没有现成代码去参考的话,还是得自己重新画图去推导一遍(个人认为还是蛮费时间的)。所以这篇博客的主要目的就是帮助我和有相同困扰的同学快速回忆起相关公式。
首先,推导所需图片如下图所示:
任意方向的矩形参数通常为 ( x , y , w , h , θ ) (x,y,w,h,\theta) (x,y,w,h,θ),在这里 θ \theta θ的角度如图所示(如格式不同,可自行转换适应)
水平矩形四参数为
(
x
,
y
,
w
1
,
h
1
)
(x,y,w_1,h_1)
(x,y,w1,h1),其中中心点坐标
(
x
,
y
)
(x,y)
(x,y)保持不变,而宽与高的表达式相对比较简单:
w
1
=
w
×
c
o
s
(
θ
)
+
h
×
s
i
n
(
θ
)
h
1
=
w
×
s
i
n
(
θ
)
+
h
×
c
o
s
(
θ
)
w_1=w\times cos(\theta)+h\times sin(\theta)\\ h_1=w\times sin(\theta)+h\times cos(\theta)
w1=w×cos(θ)+h×sin(θ)h1=w×sin(θ)+h×cos(θ)
想要转换成四个顶点坐标的话,可以做如图的辅助线进行分析(其中的三角形全等证明直接掠过 (: P));唯一已知的坐标是中心点
(
x
,
y
)
(x,y)
(x,y),那么就以中心点为起点进行计算,在这里以点A和B坐标为例:
A
x
=
x
+
(
a
1
−
a
2
)
A
y
=
y
+
(
b
1
+
b
2
)
B
x
=
x
+
(
a
1
+
a
2
)
B
y
=
y
+
(
b
1
−
b
2
)
A_x=x+(a_1-a_2)\quad A_y=y+(b_1+b_2)\\ B_x=x+(a_1+a_2)\quad B_y=y+(b_1-b_2)
Ax=x+(a1−a2)Ay=y+(b1+b2)Bx=x+(a1+a2)By=y+(b1−b2)
由对称性可知点C和D的表达式为:
C
x
=
x
−
(
a
1
−
a
2
)
C
y
=
y
−
(
b
1
+
b
2
)
D
x
=
x
−
(
a
1
+
a
2
)
D
y
=
y
−
(
b
1
−
b
2
)
C_x=x-(a_1-a_2)\quad C_y=y-(b_1+b_2)\\ D_x=x-(a_1+a_2)\quad D_y=y-(b_1-b_2)
Cx=x−(a1−a2)Cy=y−(b1+b2)Dx=x−(a1+a2)Dy=y−(b1−b2)
而
a
1
,
a
2
,
b
1
,
b
2
a_1,a_2,b_1,b_2
a1,a2,b1,b2参数的表达式可以写为:
a
1
=
h
2
×
s
i
n
(
θ
)
a
2
=
w
2
×
c
o
s
(
θ
)
b
1
=
h
2
×
c
o
s
(
θ
)
b
2
=
w
2
×
s
i
n
(
θ
)
a_1=\frac{h}{2}\times sin(\theta)\quad a_2=\frac{w}{2}\times cos(\theta)\\ b_1=\frac{h}{2}\times cos(\theta)\quad b_2=\frac{w}{2}\times sin(\theta)
a1=2h×sin(θ)a2=2w×cos(θ)b1=2h×cos(θ)b2=2w×sin(θ)
最终四个点的坐标为:
A
x
=
x
+
(
h
2
×
s
i
n
(
θ
)
−
w
2
×
c
o
s
(
θ
)
)
A
y
=
y
+
(
h
2
×
c
o
s
(
θ
)
+
w
2
×
s
i
n
(
θ
)
)
B
x
=
x
+
(
h
2
×
s
i
n
(
θ
)
+
w
2
×
c
o
s
(
θ
)
)
B
y
=
y
+
(
h
2
×
c
o
s
(
θ
)
−
w
2
×
s
i
n
(
θ
)
)
C
x
=
x
−
(
h
2
×
s
i
n
(
θ
)
−
w
2
×
c
o
s
(
θ
)
)
C
y
=
y
−
(
h
2
×
c
o
s
(
θ
)
+
w
2
×
s
i
n
(
θ
)
)
D
x
=
x
−
(
h
2
×
s
i
n
(
θ
)
+
w
2
×
c
o
s
(
θ
)
)
D
y
=
y
−
(
h
2
×
c
o
s
(
θ
)
−
w
2
×
s
i
n
(
θ
)
)
A_x=x+(\frac{h}{2}\times sin(\theta)-\frac{w}{2}\times cos(\theta))\quad A_y=y+(\frac{h}{2}\times cos(\theta)+\frac{w}{2}\times sin(\theta))\\ B_x=x+(\frac{h}{2}\times sin(\theta)+\frac{w}{2}\times cos(\theta))\quad B_y=y+(\frac{h}{2}\times cos(\theta)-\frac{w}{2}\times sin(\theta))\\ C_x=x-(\frac{h}{2}\times sin(\theta)-\frac{w}{2}\times cos(\theta))\quad C_y=y-(\frac{h}{2}\times cos(\theta)+\frac{w}{2}\times sin(\theta))\\ D_x=x-(\frac{h}{2}\times sin(\theta)+\frac{w}{2}\times cos(\theta))\quad D_y=y-(\frac{h}{2}\times cos(\theta)-\frac{w}{2}\times sin(\theta))
Ax=x+(2h×sin(θ)−2w×cos(θ))Ay=y+(2h×cos(θ)+2w×sin(θ))Bx=x+(2h×sin(θ)+2w×cos(θ))By=y+(2h×cos(θ)−2w×sin(θ))Cx=x−(2h×sin(θ)−2w×cos(θ))Cy=y−(2h×cos(θ)+2w×sin(θ))Dx=x−(2h×sin(θ)+2w×cos(θ))Dy=y−(2h×cos(θ)−2w×sin(θ))
如有错误,欢迎指正!!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。