/* Calculates area of a contour or contour segment */
CVAPI(double) cvContourArea( const CvArr* contour,
- CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ));
+ CvSlice slice CV_DEFAULT(CV_WHOLE_SEQ),
+ int oriented CV_DEFAULT(0));
/* Finds minimum area rotated rectangle bounding a set of points */
CVAPI(CvBox2D) cvMinAreaRect2( const CvArr* points,
CV_EXPORTS double arcLength( const Mat& curve, bool closed );
CV_EXPORTS Rect boundingRect( const Mat& points );
-CV_EXPORTS double contourArea( const Mat& contour );
+CV_EXPORTS double contourArea( const Mat& contour, bool oriented=false );
CV_EXPORTS RotatedRect minAreaRect( const Mat& points );
CV_EXPORTS void minEnclosingCircle( const Mat& points,
Point2f& center, float& radius );
// area may be positive or negative - in accordance with the
// contour orientation
if( result->total == 4 &&
- fabs(cvContourArea(result,CV_WHOLE_SEQ)) > 1000 &&
+ cvContourArea(result,CV_WHOLE_SEQ,0) > 1000 &&
cvCheckContourConvexity(result) )
{
s = 0;
}
-double cv::contourArea( const Mat& contour )
+double cv::contourArea( const Mat& contour, bool oriented )
{
CV_Assert(contour.isContinuous() &&
(contour.depth() == CV_32S || contour.depth() == CV_32F) &&
((contour.rows == 1 && contour.channels() == 2) ||
contour.cols*contour.channels() == 2));
CvMat _contour = contour;
- return cvContourArea(&_contour);
+ return cvContourArea(&_contour, CV_WHOLE_SEQ, oriented);
}
/* external contour area function */
CV_IMPL double
-cvContourArea( const void *array, CvSlice slice )
+cvContourArea( const void *array, CvSlice slice, int oriented )
{
double area = 0;
IPPI_CALL( icvContourSecArea( contour, slice, &area ));
}
- return area;
+ return oriented ? area : fabs(area);
}