如何在 cv2.ellipse 图形中填充颜色?

Hit*_*esh 0 python opencv

我有这个代码。它获取图像并在定义的点上绘制椭圆。就像这个示例一样。但我正在努力弄清楚如何填充颜色?

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
Run Code Online (Sandbox Code Playgroud)

alk*_*asm 5

使用负值作为厚度参数。从文档中cv.ellipse()

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

OpenCV 的所有闭合形状绘制函数都是如此。如果您想要填充和单独的描边,只需先绘制填充的椭圆,然后在顶部绘制描边即可。