-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMatrixRotate.cpp
More file actions
39 lines (31 loc) · 779 Bytes
/
MatrixRotate.cpp
File metadata and controls
39 lines (31 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* describe:矩阵旋转
* author: andrewrong
* */
#include <iostream>
#include <string>
#include <fstream>
#include "opencv/cv.h"
#include "opencv/highgui.h"
using namespace std;
void MatrixRotate(int x,int y,float degree,int& rotatedX,int& rotatedY)
{
float map[2];
map[0] = x;
map[1] = y;
CvMat mat = cvMat(2,1,CV_32F,map);
double angle = (degree * CV_PI) / 180.0;
double sina = sin(angle);
double cosa = cos(angle);
float mulMap[4];
CvMat mulMat = cvMat(2,2,CV_32F,mulMap);
mulMap[0] = cosa;
mulMap[1] = sina;
mulMap[2] = -sina;
mulMap[3] = cosa;
float dst[2] = {0};
CvMat dstMat = cvMat(2,1,CV_32F,dst);
cvGEMM(&mulMat,&mat,1,NULL,0,&dstMat,0);
rotatedX = dst[0];
rotatedY = dst[1];
}