Python opencv fill circle

Python opencv fill circle

In all the above functions, you will see some common arguments as given below:

  • img : The image where you want to draw the shapes
  • color : Color of the shape. for BGR, pass it as a tuple, eg: (255,0,0) for blue. For grayscale, just pass the scalar value.
  • thickness : Thickness of the line or circle etc. If -1 is passed for closed figures like circles, it will fill the shape. default thickness = 1
  • lineType : Type of line, whether 8-connected, anti-aliased line etc. By default, it is 8-connected.cv.LINE_AA gives anti-aliased line which looks great for curves.

Drawing Line

To draw a line, you need to pass starting and ending coordinates of line. We will create a black image and draw a blue line on it from top-left to bottom-right corners.

Drawing Rectangle

To draw a rectangle, you need top-left corner and bottom-right corner of rectangle. This time we will draw a green rectangle at the top-right corner of image.

Drawing Circle

To draw a circle, you need its center coordinates and radius. We will draw a circle inside the rectangle drawn above.

Drawing Ellipse

To draw the ellipse, we need to pass several arguments. One argument is the center location (x,y). Next argument is axes lengths (major axis length, minor axis length). angle is the angle of rotation of ellipse in anti-clockwise direction. startAngle and endAngle denotes the starting and ending of ellipse arc measured in clockwise direction from major axis. i.e. giving values 0 and 360 gives the full ellipse. For more details, check the documentation of cv.ellipse(). Below example draws a half ellipse at the center of the image.

Drawing Polygon

To draw a polygon, first you need coordinates of vertices. Make those points into an array of shape ROWSx1x2 where ROWS are number of vertices and it should be of type int32. Here we draw a small polygon of with four vertices in yellow color.

Note If third argument is False, you will get a polylines joining all the points, not a closed shape. cv.polylines() can be used to draw multiple lines. Just create a list of all the lines you want to draw and pass it to the function. All lines will be drawn individually. It is a much better and faster way to draw a group of lines than calling cv.line() for each line.

Adding Text to Images:

To put texts in images, you need specify following things.

  • Text data that you want to write
  • Position coordinates of where you want put it (i.e. bottom-left corner where data starts).
  • Font type (Check cv.putText() docs for supported fonts)
  • Font Scale (specifies the size of font)
  • regular things like color, thickness, lineType etc. For better look, lineType = cv.LINE_AA is recommended.
Читайте также:  Php ini open basedir disable

We will write OpenCV on our image in white color.

Result

So it is time to see the final result of our drawing. As you studied in previous articles, display the image to see it.

drawing_result.jpg

Additional Resources

Exercises

doxygen

Generated on Tue Jul 18 2023 23:26:23 for OpenCV by 1.8.13

Источник

Python opencv fill circle

  • Image Resizing using OpenCV | Python
  • Python OpenCV | cv2.erode() method
  • Python | Image blurring using OpenCV
  • Python OpenCV | cv2.copyMakeBorder() method
  • Python | Grayscaling of Images using OpenCV
  • Image Processing in Python (Scaling, Rotating, Shifting and Edge Detection)
  • Erosion and Dilation of images using OpenCV in python
  • OpenCV Python Program to analyze an image using Histogram
  • Histograms Equalization in OpenCV
  • Python | Thresholding techniques using OpenCV | Set-1 (Simple Thresholding)
  • Python | Thresholding techniques using OpenCV | Set-2 (Adaptive Thresholding)
  • Python | Thresholding techniques using OpenCV | Set-3 (Otsu Thresholding)
  • OpenCV: Segmentation using Thresholding
  • Python OpenCV | cv2.cvtColor() method
  • Filter Color with OpenCV
  • Python | Denoising of colored images using opencv
  • Python | Visualizing image in different color spaces
  • Find Co-ordinates of Contours using OpenCV | Python
  • Python | Bilateral Filtering
  • Image Inpainting using OpenCV
  • Python | Intensity Transformation Operations on Images
  • Python | Image Registration using OpenCV
  • Python | Background subtraction using OpenCV
  • Background Subtraction in an Image using Concept of Running Average
  • Python | Foreground Extraction in an Image using Grabcut Algorithm
  • Python | Morphological Operations in Image Processing (Opening) | Set-1
  • Python | Morphological Operations in Image Processing (Closing) | Set-2
  • Python | Morphological Operations in Image Processing (Gradient) | Set-3
  • Image segmentation using Morphological operations in Python
  • Image Translation using OpenCV | Python
  • Image Pyramid using OpenCV | Python
  • Python | Program to extract frames using OpenCV
  • Displaying the coordinates of the points clicked on the image using Python-OpenCV
  • White and black dot detection using OpenCV | Python
  • Python | OpenCV BGR color palette with trackbars
  • Draw a rectangular shape and extract objects using Python’s OpenCV
  • Invisible Cloak using OpenCV | Python Project
  • ML | Unsupervised Face Clustering Pipeline
  • Saving Operated Video from a webcam using OpenCV
  • Face Detection using Python and OpenCV with webcam
  • Opening multiple color windows to capture using OpenCV in Python
  • Python | Play a video in reverse mode using OpenCV
  • Template matching using OpenCV in Python
  • Cartooning an Image using OpenCV – Python
  • Vehicle detection using OpenCV Python
  • Count number of Faces using Python – OpenCV
  • Live Webcam Drawing using OpenCV
  • Detect and Recognize Car License Plate from a video in real time
  • Build GUI Application Pencil Sketch from Photo in Python
  • Python OpenCV – Drowsiness Detection
  • Face Alignment with OpenCV and Python
  • Age Detection using Deep Learning in OpenCV
  • Right and Left Hand Detection Using Python
  • OpenCV Python: How to detect if a window is closed?
  • Save frames of live video with timestamps – Python OpenCV
  • Detecting low contrast images with OpenCV, scikit-image, and Python
  • Animate image using OpenCV in Python
  • Drawing a cross on an image with OpenCV
  • Blur and anonymize faces with OpenCV and Python
  • Face detection using Cascade Classifier using OpenCV-Python
  • Real time object color detection using OpenCV
  • Python – Writing to video with OpenCV
  • Add image to a live camera feed using OpenCV-Python
  • Face and Hand Landmarks Detection using Python – Mediapipe, OpenCV
  • Emotion Based Music Player – Python Project
  • Realtime Distance Estimation Using OpenCV – Python
  • Webcam QR code scanner using OpenCV
  • Color Identification in Images using Python – OpenCV
  • Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
  • Opencv Python program for Face Detection
  • Image Resizing using OpenCV | Python
  • Python OpenCV | cv2.erode() method
  • Python | Image blurring using OpenCV
  • Python OpenCV | cv2.copyMakeBorder() method
  • Python | Grayscaling of Images using OpenCV
  • Image Processing in Python (Scaling, Rotating, Shifting and Edge Detection)
  • Erosion and Dilation of images using OpenCV in python
  • OpenCV Python Program to analyze an image using Histogram
  • Histograms Equalization in OpenCV
  • Python | Thresholding techniques using OpenCV | Set-1 (Simple Thresholding)
  • Python | Thresholding techniques using OpenCV | Set-2 (Adaptive Thresholding)
  • Python | Thresholding techniques using OpenCV | Set-3 (Otsu Thresholding)
  • OpenCV: Segmentation using Thresholding
  • Python OpenCV | cv2.cvtColor() method
  • Filter Color with OpenCV
  • Python | Denoising of colored images using opencv
  • Python | Visualizing image in different color spaces
  • Find Co-ordinates of Contours using OpenCV | Python
  • Python | Bilateral Filtering
  • Image Inpainting using OpenCV
  • Python | Intensity Transformation Operations on Images
  • Python | Image Registration using OpenCV
  • Python | Background subtraction using OpenCV
  • Background Subtraction in an Image using Concept of Running Average
  • Python | Foreground Extraction in an Image using Grabcut Algorithm
  • Python | Morphological Operations in Image Processing (Opening) | Set-1
  • Python | Morphological Operations in Image Processing (Closing) | Set-2
  • Python | Morphological Operations in Image Processing (Gradient) | Set-3
  • Image segmentation using Morphological operations in Python
  • Image Translation using OpenCV | Python
  • Image Pyramid using OpenCV | Python
  • Python | Program to extract frames using OpenCV
  • Displaying the coordinates of the points clicked on the image using Python-OpenCV
  • White and black dot detection using OpenCV | Python
  • Python | OpenCV BGR color palette with trackbars
  • Draw a rectangular shape and extract objects using Python’s OpenCV
  • Invisible Cloak using OpenCV | Python Project
  • ML | Unsupervised Face Clustering Pipeline
  • Saving Operated Video from a webcam using OpenCV
  • Face Detection using Python and OpenCV with webcam
  • Opening multiple color windows to capture using OpenCV in Python
  • Python | Play a video in reverse mode using OpenCV
  • Template matching using OpenCV in Python
  • Cartooning an Image using OpenCV – Python
  • Vehicle detection using OpenCV Python
  • Count number of Faces using Python – OpenCV
  • Live Webcam Drawing using OpenCV
  • Detect and Recognize Car License Plate from a video in real time
  • Build GUI Application Pencil Sketch from Photo in Python
  • Python OpenCV – Drowsiness Detection
  • Face Alignment with OpenCV and Python
  • Age Detection using Deep Learning in OpenCV
  • Right and Left Hand Detection Using Python
  • OpenCV Python: How to detect if a window is closed?
  • Save frames of live video with timestamps – Python OpenCV
  • Detecting low contrast images with OpenCV, scikit-image, and Python
  • Animate image using OpenCV in Python
  • Drawing a cross on an image with OpenCV
  • Blur and anonymize faces with OpenCV and Python
  • Face detection using Cascade Classifier using OpenCV-Python
  • Real time object color detection using OpenCV
  • Python – Writing to video with OpenCV
  • Add image to a live camera feed using OpenCV-Python
  • Face and Hand Landmarks Detection using Python – Mediapipe, OpenCV
  • Emotion Based Music Player – Python Project
  • Realtime Distance Estimation Using OpenCV – Python
  • Webcam QR code scanner using OpenCV
  • Color Identification in Images using Python – OpenCV
  • Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
  • Opencv Python program for Face Detection
Читайте также:  Найти индекс минимального элемента питон

Источник

How to Draw Filled Circle in OpenCV Python

How to Draw Filled Circle in OpenCV Python

You can draw a filled circle in OpenCV Python by following the given steps. I highly recommend you get the “Computer Vision: Models, Learning, and Inference Book” to learn Computer Vision. How to Draw Filled Circle in OpenCV Python

Step 1

Import the OpenCV library. If OpenCV is not installed in your system then first install it using This Method.

import cv2 #cv2 is used for OpenCV library

Step 2

Now read the image from the location. In my case “C:\\AiHints” is the location and “AI.jpg” is the name of the image. Change it according to your image location and name.

image = cv2.imread("C:\\AiHints\\AI.jpg") #imread is use to read an image from a location

Step 3

Now I will draw a filled circle on the image using the following code. In the code, (80,80) is the center point, and 50 is the diameter of the circle. After that, I will specify a color for the circle (0,255,0) that is green color. The last parameter in both methods is for the filled circle. You can change any value according to your requirement.

# Both methods will give same results. You can use any method to draw filled circle. image2 = cv2.circle(image,(80,80), 50, (0,255,0),-1) #Method 1 image2 = cv2.circle(image,(80,80), 50, (0,255,0),cv2.FILLED) #Method 2

Step 4

To display the image in a specified window use ”imshow” function.

cv2.imshow("Green Filled Circle on Image",image2)

Step 5

“waitKey(0)” will display a window until any key is pressed. “destroyAllWindows()” will destroy all the windows that we created.

cv2.waitKey(0) cv2.destroyAllWindows()

Output

Green Filled Circle on Image using OpenCV

Green Filled Circle on Image using OpenCV

Читайте также:  Character java все методы

Источник

Оцените статью