Reputation: 31
I have this code. Which takes image and draws ellipse over the defined point.Like this sample. But i am struggling to figure out how can i fill color in it?
def annotate_image(annotations, i):
file_name = annotations[i][0]
PATH= "/content/content/train/Class1_def/"+file_name+'.png'
img=cv2.imread(PATH)
#print(img.shape)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
semi_major= int(float(annotations[i][1]))
semi_minor= int(float(annotations[i][2]))
rotation= int(float(annotations[i][3]))
x_pos_ellip= int(float(annotations[i][4]))
y_pos_ellip= int(float(annotations[i][5]))
center_coordinates= (x_pos_ellip, y_pos_ellip)
axesLength= (semi_major,semi_minor)
angle= int(float(rotation))
startAngle = 0
endAngle = 360
# Red color
color = (255, 0, 0)
# Line thickness
thickness = 2
cv2.ellipse(img, center_coordinates, axesLength,
angle, startAngle, endAngle, color, thickness)
return img
Upvotes: 1
Views: 3023
Reputation: 23012
Use a negative value for the thickness parameter. From the docs on cv.ellipse()
:
thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.
This is true of all of OpenCV's drawing functions for closed shapes. If you want both a fill and a separate stroke, simply draw the filled ellipse first, then the stroke on top.
Upvotes: 5