Draw a circle above the opencv image.

I use python and opencv to get a webcam image, and I want to know how to draw a circle above my image, just a simple green circle with transparent filling

enter image description here

my code is:

import cv2 import numpy import sys if __name__ == '__main__': #get current frame from webcam cam = cv2.VideoCapture(0) img = cam.read() #how draw a circle???? cv2.imshow('WebCam', img) cv2.waitKey() 

Thanks in advance.

+4
source share
3 answers
 cv2.circle(img, center, radius, color, thickness=1, lineType=8, shift=0) → None Draws a circle. Parameters: img (CvArr) – Image where the circle is drawn center (CvPoint) – Center of the circle radius (int) – Radius of the circle color (CvScalar) – Circle color thickness (int) – Thickness of the circle outline if positive, otherwise this indicates that a filled circle is to be drawn lineType (int) – Type of the circle boundary, see Line description shift (int) – Number of fractional bits in the center coordinates and radius value 

Use the thickness option for the border only.

+7
source

Additional Information Only:

The "center" parameter of the OpenCV cv2.circle () drawing function accepts a tuple of two integers. The first is the location of the width, and the second is the location of the height. This ordering is different from regular array indexing. The following example demonstrates the problem.

 import numpy as np import cv2 height, width = 150, 200 img = np.zeros((height, width, 3), np.uint8) img[:, :] = [255, 255, 255] # Pixel position to draw at row, col = 20, 100 # Draw a square with position 20, 100 as the top left corner for i in range(row, 30): for j in range(col, 110): img[i, j] = [0, 0, 255] # Will the following draw a circle at (20, 100)? # Ans: No. It will draw at row index 100 and column index 20. cv2.circle(img,(row, col), 5, (0,255,0), -1) cv2.imwrite("square_circle_opencv.jpg", img) 

python opencv cv2.circle center indexing problem

+4
source

try

 cv2.circle(img, center, radius, color[, thickness[, lineType[, shift]]]) 

See more details.

+1
source

Source: https://habr.com/ru/post/1480131/


All Articles