使用OpenCV旋转点周围的点

问题描述 投票:16回答:5

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

我正在寻找这样的函数:

Point2f rotatePoint(Point2f p1, Point2f center, float angle)
{
    /* MAGIC */
}
c++ opencv rotation point
5个回答
30
投票

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

  1. 通过枢轴点的负数转换点
  2. 使用标准公式旋转该点以进行2-d(或3-d)旋转
  3. 翻译回来

轮换的标准方程是:

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

y'= x sin(alpha)+ cos(alpha)

让我们以Point(2,2)为中心点(15,5)45度的例子。

首先,翻译:

c =(15.5) - (2,2)=(13.3)

现在旋转45°:

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

最后,翻译回来:

c = c +(2,2)=(i.07 ..,13.31 ..)

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


7
投票

要通过角度qazxsw poi围绕qazxsw poi旋转点qazxsw poi:

p1 = (x1, y1)

其中p (x0, y0)是点a的新位置


2
投票

如果你已经有x2 = ((x1 - x0) * cos(a)) - ((y1 - y0) * sin(a)) + x0; y2 = ((x1 - x0) * sin(a)) + ((y1 - y0) * cos(a)) + y0; 形式的点,你可以改变它的角度来旋转点。

(x2, y2)

2
投票

这可能有所帮助

p1

1
投票

我正在寻找图像的任何像素坐标的转换,我很难通过谷歌搜索找到它。不知何故,我发现一个python代码的链接正常工作,这有助于我理解这个问题:RotatedRect

以下是相应的C ++代码,如果有人正在寻找它:

//RotatedRect myRect;
Point2f oldPoints[4];
myRect.points(oldPoints);  //gives existing points of the rectangle.
myRect.angle = 0;          //change the angle.
Point2f newPoints[4];
myRect.points(newPoints);  //gives rotated points of the rectangle.
© www.soinside.com 2019 - 2024. All rights reserved.