# How to get the distance between the major and minor axes an ellipse?

**URL:** <https://forum.opencv.org/t/how-to-get-the-distance-between-the-major-and-minor-axes-an-ellipse/4761>\
**Category:** Python\
**Tags:** imgproc\
**Created:** [August 14, 2021, 7:38am UTC](https://forum.opencv.org/t/how-to-get-the-distance-between-the-major-and-minor-axes-an-ellipse/4761 "2021-08-14T07:38:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abbeykev](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@abbeykev](https://forum.opencv.org/u/abbeykev)\
**Post date:** [August 14, 2021, 7:38am UTC](https://forum.opencv.org/t/how-to-get-the-distance-between-the-major-and-minor-axes-an-ellipse/4761/1 "2021-08-14T07:38:00Z")

</div>

I am trying to use opencv in python to detect the distance between the major and bottom axes of an ellipse in an image, so far I detect the centroid. Any ideas to get the axes of the ellipse?

Thanks a lot

```auto
import time
import sys
sys.path.append('/usr/local/lib/python3.9/site-packages')

import cv2
import numpy as np
  
# Read image.
img = cv2.imread('./imagenes/junio100.bmp', cv2.IMREAD_COLOR)
  
# Convert to grayscale.
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
# Blur using 3 * 3 kernel.
gray_blurred = cv2.blur(gray, (3, 3))
  
# Apply Hough transform on the blurred image.
detected_circles = cv2.HoughCircles(gray_blurred, 
                   cv2.HOUGH_GRADIENT, 1, 20, param1 = 50,
               param2 = 30, minRadius = 1, maxRadius = 40)
  
# Draw circles that are detected.
if detected_circles is not None:
  
    # Convert the circle parameters a, b and r to integers.
    detected_circles = np.uint16(np.around(detected_circles))
  
    for pt in detected_circles[0, :]:
        a, b, r = pt[0], pt[1], pt[2]
  
        # Draw the circumference of the circle.
        cv2.circle(img, (a, b), r, (0, 255, 0), 2)
  
        # Draw a small circle (of radius 1) to show the center.
        cv2.circle(img, (a, b), 1, (0, 0, 255), 3)
        
        print ("axis x:",(pt[0]))
        print ("axis y:",(pt[1]))
        print ("Diameter:",(pt[2]))
        cv2.imshow("Detected Circle", img)
        cv2.waitKey(0)

```

 ![Screen Shot 2021-08-10 at 22.46.25](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/8/88ab13cdaac93764cdfa201325a80be08e288277.jpeg)  
 ![Screen Shot 2021-08-10 at 22.44.50](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/d/d1b18a7393a2beb70fa4e1459372f0bdf5f73beb.png)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 14, 2021, 8:13am UTC](https://forum.opencv.org/t/how-to-get-the-distance-between-the-major-and-minor-axes-an-ellipse/4761/2 "2021-08-14T08:13:09Z")

</div>

if you had contours, you could try to [fit an ellipse](https://docs.opencv.org/master/d3/dc0/group __imgproc__ shape.html#gaf259efaad93098103d6c27b9e4900ffa)
