What is the best way to draw multi-color segmented circle using OpenCV like below?
What I found, it can be:
- Using cv.fillPoly Many points are required for an arcs accurate drawing, the number of segments is several hundred;
- Using cv.line by rotating the line in a circle;
- Using cv.line by rotating whole image like in this similar case.
Advertisement
Answer
Using cv.ellipse
you can draw segments pretty easily:
JavaScript
x
21
21
1
from matplotlib import pyplot as plt
2
import cv2
3
import numpy as np
4
import random
5
6
ANGLE_DELTA = 360 // 8
7
8
img = np.zeros((700, 700, 3), np.uint8)
9
img[::] = 255
10
11
for size in range(300, 0, -100):
12
for angle in range(0, 360, ANGLE_DELTA):
13
r = random.randint(0, 256)
14
g = random.randint(0, 256)
15
b = random.randint(0, 256)
16
cv2.ellipse(img, (350, 350), (size, size), 0, angle, angle + ANGLE_DELTA, (r, g, b), cv2.FILLED)
17
18
plt.gcf().set_size_inches((8, 8))
19
plt.imshow(img)
20
plt.show()
21
gives