如何在cv2.椭圆图形中填充颜色



我有这段代码。它拍摄图像并在定义的点上绘制椭圆。就像这个样本。但我很难弄清楚如何在里面填充颜色?

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

使用负值作为厚度参数。来自cv.ellipse():上的文档

厚度椭圆弧轮廓的厚度,如果为正。否则,这表示要绘制一个填充的椭圆扇区。

这适用于OpenCV针对闭合形状的所有绘图函数。如果您想要一个填充和一个单独的笔划,只需先绘制填充的椭圆,然后在顶部绘制笔划。

设置thickness = -1,这将填充其中的颜色。

最新更新