原图:
绕垂直轴旋转:
绕水平轴旋转:
绕中心点旋转:
Mat warpPerspective(Mat src, float angle, int mode)
{
angle *= 0.0174533;
int height = src.rows;
int width = src.cols;
Mat outMat(height, width, CV_8U, 255);
double ri0 = height*0.5;
double rj0 = width*0.5;
float ratio = sin(angle);
if (mode == 1)
{
double ri0 = height*0.5;
double rj0 = width*0.5;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int srci = -(j - rj0)*sin(angle) + (i - ri0)*cos(angle) + ri0;
int srcj = (j - rj0)*cos(angle) + (i - ri0)*sin(angle) + rj0;
if (srci >= 0 && srci < width && srcj >= 0 && srcj < height)
outMat.ptr<uchar>(i)[j] = src.ptr<uchar>(srci)[srcj];
}
}
}