Skip to content Skip to sidebar Skip to footer

How To Find The Area Of An Ellipse Obtained Using Cv.fitellipse(contour)?

I'm obtaining the an ellipse by using ellipse = cv2.fitEllipse(cnt). It returns a tuple of 3 elements, but I'm unable to find what any of that depicts. I want to find the area of t

Solution 1:

fitEllipse returns a tuple of three elements (as you say), which define the bounding box of the ellipse. I'll use the following line to reference those elements:

(x, y), (MA, ma), angle = cv2.fitEllipse(cnt)

The only relevant information here is (MA, ma), which contains the lengths of the major axis and minor axis, in that order. The area of an ellipse is simply pi times the product of the major axis and the minor axis. (Therefore the location and rotation are irrelevant.) So you would calculate the area of this ellipse using

A = PI * MA * ma

Solution 2:

the function cv2.fitEllipse(.) returns elements for RotatedRect that is minimum bounding rectangle covering the ellipse.

To find the area you can either get the area of the bounding rect or directly from the contour of the ellipse contourArea

Solution 3:

You can calculate using returned elements of ellipse = cv2.fitEllipse(cnt)

DoubleH= ellipse.size.height;
  DoubleW= ellipse.size.weight;
  Doubleellipse_area= CV_PI * (H/2.0) * (W/2.0) 

Divide H and W by 2.0 for Max and Min radiuses

Post a Comment for "How To Find The Area Of An Ellipse Obtained Using Cv.fitellipse(contour)?"