Draw an ellipse on an image with OpenCV

In OpenCV, use the cv2.ellipse() function to draw a rectangle on an image. First, we will read the image using the imread() function in OpenCV.

Let us now see the example:

The following is the output:

Draw an ellipse on an image with OpenCV
Explanation:

This Python script employs the OpenCV library to load, resize, and draw an ellipse on an image:

  • It begins by importing the OpenCV library, and then reads an image from the specified file path, loading it in color.
  • The image is resized to dimensions of 600×600 pixels using the cv2.resize() function.
  • After resizing, the script draws a blue ellipse on the image. The cv2.ellipse() function is used, with the first argument specifying the image, the second argument specifying the center coordinates of the ellipse (150, 50), the third argument specifying the axes lengths (80, 20), the fourth argument specifying the rotation angle (5 degrees), the fifth and sixth arguments specifying the start and end angles (0 and 360 degrees), the seventh argument specifying the color (blue), and the eighth argument specifying the thickness (where -1 fills the ellipse).
  • Finally, the script displays the resized image with the drawn ellipse in a window titled “Image Resized:” using cv2.imshow(), waits for a key press with cv2.waitKey(0), and closes all OpenCV windows with cv2.destroyAllWindows().
  • This process allows users to view the modified image with the drawn ellipse and close the display window at their convenience.

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Draw a rectangle on an image with OpenCV
Draw a line on an image with OpenCV
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading