【问题标题】:How to draw multi-color segmented circle using OpenCV?如何使用 OpenCV 绘制多色分段圆?
【发布时间】:2021-09-29 03:57:31
【问题描述】:

如下所示,使用 OpenCV 绘制多色分段圆的最佳方法是什么?

我发现的,可以是:

  1. 使用cv.fillPoly 精确绘制圆弧需要很多点,段数为数百;
  2. 使用cv.line 将线旋转一圈;
  3. 使用 cv.line 旋转整个图像,就像在 similar case 中一样。

【问题讨论】:

  • 您可以使用cv.ellipse 从最外面的部分开始绘制填充圆弧。然后用内部零件画出来。
  • @Timo 谢谢,这可能是最好的方法,它有效。

标签: python c++ opencv


【解决方案1】:

使用cv.ellipse,您可以非常轻松地绘制线段:

from matplotlib import pyplot as plt
import cv2
import numpy as np
import random

ANGLE_DELTA = 360 // 8

img = np.zeros((700, 700, 3), np.uint8)
img[::] = 255

for size in range(300, 0, -100):
    for angle in range(0, 360, ANGLE_DELTA):
        r = random.randint(0, 256)
        g = random.randint(0, 256)
        b = random.randint(0, 256)
        cv2.ellipse(img, (350, 350), (size, size), 0, angle, angle + ANGLE_DELTA, (r, g, b), cv2.FILLED)

plt.gcf().set_size_inches((8, 8))
plt.imshow(img)
plt.show()

给予

【讨论】:

    猜你喜欢
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    相关资源
    最近更新 更多