52 return number < 0.0 ? ceil(number - 0.5) : floor(number + 0.5);
56 return (M_PI*degree)/180.0;
60 return (180*radian)/M_PI;
66 if((degree >= 0 && degree <= 90) || (degree >= 181 && degree <= 270)) {
67 canvas.height =
round((h*fabs(sin(angle+radian)))*2);
68 canvas.width =
round((h*fabs(cos(M_PI-angle+radian)))*2);
70 canvas.height =
round((h*fabs(sin(M_PI-angle+radian)))*2);
71 canvas.width =
round((h*fabs(cos(angle+radian)))*2);
95 map<string,int> m = map<string,int>();
97 if(newSize.height >= original.height) {
98 m[
"top"] =
round((newSize.height-original.height)/2.0);
99 m[
"bottom"] =
round((newSize.height-original.height)/2.0);
105 if(newSize.width >= original.width) {
106 m[
"left"] =
round((newSize.width-original.width)/2.0);
107 m[
"right"] =
round((newSize.width-original.width)/2.0);
117 map<string,Point> m = map<string,Point>();
119 m[
"tl"] = Point(margins[
"left"],margins[
"top"]);
120 m[
"tr"] = Point(margins[
"left"]+original.width,margins[
"top"]);
121 m[
"bl"] = Point(margins[
"left"],margins[
"top"]+original.height);
122 m[
"br"] = Point(margins[
"left"]+original.width,margins[
"top"]+original.height);
130 map<string,Point> m = map<string,Point>();
135 round(s.width/2.0+h*cos(M_PI-angle+radian)),
136 round(s.height/2.0-h*sin(M_PI-angle+radian)));
142 round(s.width/2.0+h*cos(angle+radian)),
143 round(s.height/2.0-h*sin(angle+radian)));
145 if(top>m[
"tr"].y) top=m[
"tr"].y;
146 if(left>m[
"tr"].x) left=m[
"tr"].x;
149 round(s.width/2.0+h*cos(-angle+radian)),
150 round(s.height/2.0-h*sin(-angle+radian)));
152 if(top>m[
"br"].y) top=m[
"br"].y;
153 if(left>m[
"br"].x) left=m[
"br"].x;
156 round(s.width/2.0+h*cos(M_PI+angle+radian)),
157 round(s.height/2.0-h*sin(M_PI+angle+radian)));
159 if(top>m[
"bl"].y) top=m[
"bl"].y;
160 if(left>m[
"bl"].x) left=m[
"bl"].x;
181 tmp = abs(a.x-b.x)/2.0;
183 if(b.x <= a.x) c.x =
round(tmp+b.x);
184 else c.x =
round(tmp+a.x);
186 tmp = abs(a.y-b.y)/2.0;
188 if(b.y <= a.y) c.y =
round(tmp+b.y);
189 else c.y =
round(tmp+a.y);
195 map<string,Point> m = map<string,Point>();
217 }
else if(a.y-b.y==0) {
222 equation.
m = (double)(a.y-b.y)/(a.x-b.x);
223 equation.
c = a.y-equation.
m*a.x;
245 equation.
m = -1.0/e.
m;
246 equation.
c = -p.x*equation.
m+p.y;
254 map<string,Equ> m = map<string,Equ>();
265 map<string,Equ> m = map<string,Equ>();
277 Point2d p = Point2d(0,0);
292 p.x = (p.y-e2.
c)/e2.
m;
297 p.x = (p.y-e1.
c)/e1.
m;
311 p.y = fabs(e1.
c*e2.
m-e2.
c*e1.
m)/fabs(e1.
m-e2.
m);
312 p.x = (p.y-e1.
c)/e1.
m;
325 Mat copy,schema,rot_mat;
326 map<string,int> margins;
327 Size img,canvas,workspace;
330 map<string,Point> original, projection, centre;
332 map<string,Equ> pEqu;
336 img = Size(src.cols,src.rows);
337 h = sqrt(pow(img.width/2.0,2) + pow(img.height/2.0,2));
338 angle = atan((
double)img.height/img.width);
342 copyMakeBorder(src,copy,margins[
"top"],margins[
"bottom"],margins[
"left"],
343 margins[
"right"],BORDER_CONSTANT,Scalar(0,0,0));
345 workspace = Size(copy.cols,copy.rows);
353 if(img.width > canvas.width || img.height > canvas.height) {
355 src_centre = Point2f(p.x,p.y);
357 src_centre = Point2f(canvas.width/2.0,canvas.height/2.0);
361 dst.create(canvas.height,canvas.width,src.channels());
362 rot_mat = getRotationMatrix2D(src_centre, degree, 1.0);
363 cv::warpAffine(copy, dst, rot_mat,canvas);
static Point getColisionPoint(Equ e1, Equ e2)
static double radianToDegree(double radian)
static double solveEquationX(Equ e, double y)
static map< string, Point > getCorners(Size &original, map< string, int > &margins)
static Equ getPerpendicular(Equ e, Point p)
static map< string, Point > getCentreBetweenOriginalsAndProjections(map< string, Point > &originals, map< string, Point > &projections)
static double degreeToRadian(double degree)
static map< string, Equ > getLinearEquationBetweenOriginalsAndProjections(map< string, Point > &originals, map< string, Point > &projections)
static map< string, Point > getProjectedCorners(Size &s, double h, double degree, double angle)
static double round(double number)
static Point getCentreBetweenPoints(Point &a, Point &b)
static double solveEquationY(Equ e, double x)
static void rotate_image(Mat &src, Mat &dst, const double degree)
helper function to rotate an image.
static Size rotationNewCanvasSize(double degree, double angle, double h)
static map< string, Equ > getPerpendicularLinearEquation(map< string, Point > &originals, map< string, Point > &projections, map< string, Point > ¢re)
static map< string, int > rotationExtraMargins(Size &original, Size &newSize)
static Equ getLinearEquation(Point &a, Point &b)