Spaces:
Sleeping
Sleeping
| 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) | |