使用 OpenCV 围绕一个点旋转一个点 [英] Rotate a point around a point with OpenCV

查看:132
本文介绍了使用 OpenCV 围绕一个点旋转一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在 OpenCV 中围绕另一个点旋转一个点?

Does anyone know how I can rotate a point around another in OpenCV?

我正在寻找这样的功能:

I am looking for a function like this:

Point2f rotatePoint(Point2f p1, Point2f center, float angle)
{
    /* MAGIC */
}

推荐答案

这些是将一个点围绕另一个点旋转一个角度 alpha 所需的步骤:

These are the steps needed to rotate a point around another point by an angle alpha:

  1. 按轴心点的负值平移该点
  2. 使用 2-d(或 3-d)旋转的标准方程旋转点
  3. 翻译回来

旋转的标准方程是:

x' = xcos(alpha) - ysin(alpha)

x' = xcos(alpha) - ysin(alpha)

y' = xsin(alpha) + ycos(alpha)

y' = xsin(alpha) + ycos(alpha)

我们以 Point(15,5) 为例,在 Point(2,2) 周围 45 度.

Let's take the example of Point(15,5) around Point(2,2) by 45 degrees.

首先,翻译:

v = (15,5) - (2,2) = (13,3)

v = (15,5) - (2,2) = (13,3)

现在旋转 45°:

v = (13*cos 45° - 3*sin 45°, 13*sin 45° + 3*cos 45°) = (7.07.., 11.31..)

v = (13*cos 45° - 3*sin 45°, 13*sin 45° + 3*cos 45°) = (7.07.., 11.31..)

最后,翻译回来:

v = v + (2,2) = (9.07.., 13.31..)

v = v + (2,2) = (9.07.., 13.31..)

注意:角度必须以弧度表示,因此将度数乘以 Pi/180

Note: Angles must be specified in radians, so multiply the number of degrees by Pi / 180

这篇关于使用 OpenCV 围绕一个点旋转一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆