unified the coordinate interpretation in RotatedRect (ticket #425)

This commit is contained in:
Vadim Pisarevsky
2010-11-29 18:14:08 +00:00
parent 4a973d4633
commit a937d9d43c
8 changed files with 51 additions and 39 deletions

View File

@@ -877,7 +877,7 @@ void ellipse2Poly( Point center, Size axes, int angle,
y = size_b * SinTable[angle];
Point pt;
pt.x = cvRound( cx + x * alpha - y * beta );
pt.y = cvRound( cy - x * beta - y * alpha );
pt.y = cvRound( cy + x * beta + y * alpha );
if( pt != prevPt )
pts.push_back(pt);
}

View File

@@ -3043,6 +3043,37 @@ void normalize( const SparseMat& src, SparseMat& dst, double a, int norm_type )
src.convertTo( dst, -1, scale );
}
////////////////////// RotatedRect //////////////////////
void RotatedRect::points(Point2f pt[]) const
{
double _angle = angle*CV_PI/180.;
float b = (float)cos(_angle)*0.5f;
float a = (float)sin(_angle)*0.5f;
pt[0].x = center.x - a*size.height - b*size.width;
pt[0].y = center.y + b*size.height - a*size.width;
pt[1].x = center.x + a*size.height - b*size.width;
pt[1].y = center.y - b*size.height - a*size.width;
pt[2].x = 2*center.x - pt[0].x;
pt[2].y = 2*center.y - pt[0].y;
pt[3].x = 2*center.x - pt[1].x;
pt[3].y = 2*center.y - pt[1].y;
}
inline Rect RotatedRect::boundingRect() const
{
Point2f pt[4];
points(pt);
Rect r(cvFloor(min(min(min(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
cvFloor(min(min(min(pt[0].y, pt[1].y), pt[2].y), pt[3].y)),
cvCeil(max(max(max(pt[0].x, pt[1].x), pt[2].x), pt[3].x)),
cvCeil(max(max(max(pt[0].y, pt[1].y), pt[2].y), pt[3].y)));
r.width -= r.x - 1;
r.height -= r.y - 1;
return r;
}
}