1、直接使用
cv::getRotationMatrix2D()
2、将四个顶点旋转角度
基本原理参考:这里写链接内容
1)先平移到center
2)进行旋转
3)重新加上偏移量
double cosv=cos(abs(rotated_rect.angle*3.1415926/180));
double sinv=sin(abs(rotated_rect.angle*3.1415926/180));
cv::Point2f rect_points[4];
rotated_rect.points(rect_points);
cout<<"angle="<<rotated_rect.angle<<",cosv="<<cosv<<",sinv="<<sinv<<endl;
for(int l=0;l<4;l++){
cv::Point2f p=rect_points[l];
p.x-=rotated_rect.center.x;
p.y-=rotated_rect.center.y;
cv::Point2f np;
np.x=cosv*p.x-sinv*p.y;
np.y=sinv*p.x+cosv*p.y;
np.x+=rotated_rect.center.x;
np.y+=rotated_rect.center.y;
cout<<"p["<<l<<"]="<<rect_points[l]<<",np="<<np<<endl;
}