Cv.ellipse() Function

If you have problem then use for-loop to draw it with different angles and you will see how it works.

import cv2
import numpy as np

steps = 10

img = np.zeros(((steps+1)*100, 200, 3), np.uint8)     # Create a black image

for number, angle in enumerate(range(0, 361, 360//steps)):
    y = 50 + 100 * number
    cv2.ellipse(img, (50, y), (50, 50), 0, angle, 360, (255, 0, 0), -1)  # Drawing an ellipse
    cv2.putText(img, f'{angle}-360', (25, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)

    cv2.ellipse(img, (150, y), (50, 50), 0, 0, angle, (0, 255, 0), -1)  # Drawing an ellipse
    cv2.putText(img, f'0-{angle}', (125, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)

cv2.imwrite('ellipse.png', img)

cv2.imshow('test', img)
cv2.waitKey(0)

import cv2
import numpy as np

steps = 10

first_animation = True

running = True
while running:

    for number, angle in enumerate(range(0, 361, 360//steps)):
        y = 50

        img = np.zeros((100, 100, 3), np.uint8)     # Create a black image
        
        if first_animation:
            cv2.ellipse(img, (50, y), (50, 50), 0, angle, 360, (0, 255, 0), -1)  # Drawing an ellipse
            cv2.putText(img, f'{angle}-360', (25, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)
        else:
            cv2.ellipse(img, (50, y), (50, 50), 0, 0, angle, (0, 255, 0), -1)  # Drawing an ellipse
            cv2.putText(img, f'0-{angle}', (25, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)

        cv2.imwrite('frame-{}-{}.png'.format(int(not first_animation), number), img)
        cv2.imshow('test', img)
        key = cv2.waitKey(250) & 0xFF
        if key == 27:
            running = False
            break

    first_animation = not first_animation

And frames converted to animated GIF with imagemagick

convert frame*.png animation.gif

animation

1 Like