File size: 1,266 Bytes
c9a11d0
 
 
 
 
 
26d88b0
c9a11d0
 
 
 
 
 
 
 
26d88b0
 
c9a11d0
 
 
 
 
 
 
 
 
 
 
 
26d88b0
 
 
c9a11d0
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import cv2
import numpy as np
import numpy.typing as npt

def blank(
    width: int=500, height: int=500,
    background: tuple[int, int, int]=(0,0,0)
) -> npt.NDArray[np.uint8]:
    img = np.zeros((height, width, 3), dtype=np.uint8)
    img[:, :, :] = background
    return img

def circle(
    width: int=500, height: int=500,
    radius: int=None,
    color: tuple[int, int, int]=(0,0,255),
    background: tuple[int, int, int]=(0,0,0)
) -> npt.NDArray[np.uint8]:
    if radius is None:
        radius = int(0.5 * max(width, height) * 0.8)
    center = (int(width/2), int(height/2))
    img = blank(
        width=width, height=height,
        background=background
    )
    return cv2.circle(img, center, radius, color, -1, cv2.LINE_AA)

def rectangle(
    width: int=500, height: int=500,
    pt1: tuple[int, int]=None, pt2: tuple[int, int]=None,
    color: tuple[int, int, int]=(0,0,255),
    background: tuple[int, int, int]=(0,0,0)
) -> npt.NDArray[np.uint8]:
    img = blank(
        width=width, height=height,
        background=background
    )
    if pt1 is None:
        pt1 = (int(0.2 * width), int(0.2 * height))
    if pt2 is None:
        pt2 = (int(0.8 * width), int(0.8 * height))
    return cv2.rectangle(img, pt1, pt2, color, -1, cv2.LINE_AA)