点矩阵旋转
程序员文章站
2022-07-14 23:18:47
...
对于棋盘格角点标定时,有些情况是棋盘格有一定角度旋转,角点也随之有一个旋转角,在写入矩阵就会有很多问题,需要对原角点按旋转角逆转回原来标准情况。
对棋盘格所有点以中心点为圆心,按顺时针旋转alpha°。
数学原理
如下图, 在2维坐标上,有一点p(x, y) , 直线opの长度为r, 直线op和x轴的正向的夹角为a。 直线op围绕原点做逆时针方向b度的旋转,到达p’ (s,t)
s = r cos(a + b) = r cos(a)cos(b) – r sin(a)sin(b) (1.1)
t = r sin(a + b) = r sin(a)cos(b) + r cos(a) sin(b) (1.2)
其中 x = r cos(a) , y = r sin(a)
代入(1.1), (1.2) ,
s = x cos(b) – y sin(b) (1.3)
t = x sin(b) + y cos(b) (1.4)
void rotatecorners(HObject &image, vector<cv::Point2f> &angleBDpoints,double angle)
{
double radian = angle * PI / 180; //注意是弧度
Mat cvb; //读取棋盘格
int indexx = 0;
int min_ = 3000;
for (int i = 0; i < angleBDpoints.size() - 1; i++)
{
if ((abs(angleBDpoints[i].x - cvb.cols / 2) + abs(angleBDpoints[i].y - cvb.rows / 2)) < min_)
{
min_ = abs(angleBDpoints[i].x - cvb.cols / 2) + abs(angleBDpoints[i].y - cvb.rows / 2);
indexx = i;
}
}
Point2f pc;
pc.x = angleBDpoints[indexx].x;
pc.y = angleBDpoints[indexx].y;
//==========顺时针
for (int i = 0; i < angleBDpoints.size(); ++i)
{
Point2f xy;
xy.x = (angleBDpoints[i].x-pc.x)*cos(radian) + (angleBDpoints[i].y-pc.y)*sin(radian)+pc.x;
xy.y = (angleBDpoints[i].y-pc.y)*cos(radian) - (angleBDpoints[i].x-pc.x)*sin(radian)+pc.y;
angleBDpoints[i] = xy;
}
}
上一篇: 点绕点旋转->点绕坐标轴旋转
下一篇: 1493:物种大交换开创的世界史