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

2024-06-21 20:32:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个密码。它拍摄图像并在定义的点上绘制椭圆。像这样sample。但我正在努力想我该如何在里面填充颜色呢

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

Tags: pathnameposimgdefcontentfloatcv2
2条回答

“厚度”参数使用负值。从docs on ^{}开始:

thickness Thickness of the ellipse arc outline, if positive. Otherwise, this indicates that a filled ellipse sector is to be drawn.

OpenCV的所有闭合形状绘图函数都是如此。如果同时需要填充和单独的笔划,只需先绘制填充椭圆,然后在顶部绘制笔划

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

相关问题 更多 >