use*_*793 16 c++ opencv point rotation
有谁知道如何在OpenCV中围绕另一个点旋转一个点?
我正在寻找这样的函数:
Point2f rotatePoint(Point2f p1, Point2f center, float angle)
{
/* MAGIC */
}
Run Code Online (Sandbox Code Playgroud)
Adr*_*ian 30
这些是围绕另一个点旋转角度α所需的步骤:
轮换的标准方程是:
x'= x cos(alpha) - y sin(alpha)
y'= x sin(alpha)+ y cos(alpha)
让我们以Point(2,2)为中心点(15,5)45度的例子.
首先,翻译:
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 = v +(2,2)=(9.07 ..,13.31 ..)
注意:角度必须以弧度指定,因此乘以度数 Pi / 180
要旋转点p1 = (x1, y1)周围p (x0, y0)的角度a:
x2 = ((x1 - x0) * cos(a)) - ((y1 - y0) * sin(a)) + x0;
y2 = ((x1 - x0) * sin(a)) + ((y1 - y0) * cos(a)) + y0;
Run Code Online (Sandbox Code Playgroud)
(x2, y2)点的新位置在哪里p1
这可能有帮助
cv::Point2f rotate2d(const cv::Point2f& inPoint, const double& angRad)
{
cv::Point2f outPoint;
//CW rotation
outPoint.x = std::cos(angRad)*inPoint.x - std::sin(angRad)*inPoint.y;
outPoint.y = std::sin(angRad)*inPoint.x + std::cos(angRad)*inPoint.y;
return outPoint;
}
cv::Point2f rotatePoint(const cv::Point2f& inPoint, const cv::Point2f& center, const double& angRad)
{
return rotate2d(inPoint - center, angRad) + center;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15848 次 |
| 最近记录: |