zerohertzLib.vision.visual ¶
Functions:
| Name | Description |
|---|---|
bbox | 여러 Bbox 시각화 |
mask | Mask 시각화 |
paste |
|
text | Text 시각화 |
_bbox ¶
_bbox(img: NDArray[uint8], box_poly: NDArray[DTypeLike], color: tuple[int, int, int], thickness: int) -> NDArray[uint8]
Bbox 시각화
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | NDArray[uint8] | Input image ( | required |
box_poly | NDArray[DTypeLike] | 하나의 bbox ( | required |
color | tuple[int, int, int] | bbox의 색 | required |
thickness | int | bbox 선의 두께 | required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | 시각화 결과 ( |
Source code in zerohertzLib/vision/visual.py
_make_text ¶
_make_text(txt: str, shape: tuple[int, int], color: tuple[int, int, int], fontsize: int) -> NDArray[uint8]
배경이 투명한 문자열 image 생성
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
txt | str | 입력 문자열 | required |
shape | tuple[int, int] | 출력 image의 shape | required |
color | tuple[int, int, int] | 문자의 색 | required |
fontsize | int | 문자의 크기 | required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | 시각화 결과 ( |
Source code in zerohertzLib/vision/visual.py
_paste ¶
target image를 img 위에 투명도를 포함하여 병합
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | NDArray[uint8] | 입력 image ( | required |
target | NDArray[uint8] | Target image ( | required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | 시각화 결과 ( |
Source code in zerohertzLib/vision/visual.py
_text ¶
_text(img: NDArray[uint8], box_cwh: NDArray[DTypeLike], txt: str, color: tuple[int, int, int], fontsize: int) -> NDArray[uint8]
단일 text 시각화
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | NDArray[uint8] | 입력 image ( | required |
box_cwh | NDArray[DTypeLike] | 문자열이 존재할 bbox ( | required |
txt | str | Image에 추가할 문자열 | required |
color | tuple[int, int, int] | 문자의 색 | required |
fontsize | int | 문자의 크기 | required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | 시각화 결과 ( |
Source code in zerohertzLib/vision/visual.py
bbox ¶
bbox(img: NDArray[uint8], box: list[int | float] | NDArray[DTypeLike], color: tuple[int, int, int] = (0, 0, 255), thickness: int = 2) -> NDArray[uint8]
여러 Bbox 시각화
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | NDArray[uint8] | Input image ( | required |
box | list[int | float] | NDArray[DTypeLike] | 하나 혹은 여러 개의 bbox ( | required |
color | tuple[int, int, int] | bbox의 색 | (0, 0, 255) |
thickness | int | bbox 선의 두께 | 2 |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | 시각화 결과 ( |
Examples:
Bbox: >>> box = np.array([[100, 200], [100, 1000], [1200, 1000], [1200, 200]]) >>> box.shape (4, 2) >>> res1 = zz.vision.bbox(img, box, thickness=10)
Bboxes: >>> boxes = np.array([[250, 200, 100, 100], [600, 600, 800, 200], [900, 300, 300, 400]]) >>> boxes.shape (3, 4) >>> res2 = zz.vision.bbox(img, boxes, (0, 255, 0), thickness=10)
Source code in zerohertzLib/vision/visual.py
mask ¶
mask(img: NDArray[uint8], mks: NDArray[bool] | None = None, poly: list[int | float] | NDArray[DTypeLike] | list[NDArray[DTypeLike]] | None = None, color: tuple[int, int, int] = (0, 0, 255), class_list: list[int | str] | None = None, class_color: dict[int | str, tuple[int, int, int]] | None = None, border: bool = True, alpha: float = 0.5) -> NDArray[uint8]
Mask 시각화
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | NDArray[uint8] | 입력 image ( | required |
mks | NDArray[bool] | None | 입력 image 위에 병합할 mask ( | None |
poly | list[int | float] | NDArray[DTypeLike] | list[NDArray[DTypeLike]] | None | 입력 image 위에 병합할 mask ( | None |
color | tuple[int, int, int] | Mask의 색 | (0, 0, 255) |
class_list | list[int | str] | None |
| None |
class_color | dict[int | str, tuple[int, int, int]] | None | Class에 따른 색 ( | None |
border | bool | Mask의 경계선 표시 여부 | True |
alpha | float | Mask의 투명도 | 0.5 |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | 시각화 결과 ( |
Examples:
Mask:
>>> H, W, _ = img.shape
>>> cnt = 30
>>> mks = np.zeros((cnt, H, W), np.uint8)
>>> for mks_ in mks:
>>> center_x = random.randint(0, W)
>>> center_y = random.randint(0, H)
>>> radius = random.randint(30, 200)
>>> cv2.circle(mks_, (center_x, center_y), radius, (True), -1)
>>> mks = mks.astype(bool)
>>> res1 = zz.vision.mask(img, mks)
>>> cls = [i for i in range(cnt)]
>>> class_list = [cls[random.randint(0, 5)] for _ in range(cnt)]
>>> class_color = {}
>>> for c in cls:
>>> class_color[c] = [random.randint(0, 255) for _ in range(3)]
>>> res2 = zz.vision.mask(img, mks, class_list=class_list, class_color=class_color)
>>> poly = np.array([[100, 400], [400, 400], [800, 900], [400, 1100], [100, 800]])
>>> res3 = zz.vision.mask(img, poly=poly)
>>> poly = zz.vision.xyxy2poly(zz.vision.poly2xyxy((np.random.rand(cnt, 4, 2) * (W, H))))
>>> res4 = zz.vision.mask(img, poly=poly, class_list=class_list, class_color=class_color)
Source code in zerohertzLib/vision/visual.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
paste ¶
paste(img: NDArray[uint8], target: NDArray[uint8], box: list[int | float] | NDArray[DTypeLike], resize: bool = False, vis: bool = False, poly: NDArray[DTypeLike] | None = None, alpha: int | None = None, gaussian: int | None = None) -> NDArray[uint8] | tuple[NDArray[uint8], NDArray[DTypeLike]]
target image를 img 위에 투명도를 포함하여 병합
Note
PIL.Image.paste 를 numpy 와 cv2 기반으로 구현
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | NDArray[uint8] | 입력 image ( | required |
target | NDArray[uint8] | Target image ( | required |
box | list[int | float] | NDArray[DTypeLike] | 병합될 영역 ( | required |
resize | bool | Target image의 resize 여부 | False |
vis | bool | 지정한 영역 ( | False |
poly | NDArray[DTypeLike] | None | 변형된 좌표 ( | None |
alpha | int | None |
| None |
gaussian | int | None | 자연스러운 병합을 위해 | None |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | tuple[NDArray[uint8], NDArray[DTypeLike]] | 시각화 결과 ( |
Examples:
Without Poly:
>>> poly = np.array([[100, 400], [400, 400], [800, 900], [400, 1100], [100, 800]])
>>> target = zz.vision.cutout(img, poly, 200)
>>> res1 = zz.vision.paste(img, target, [200, 200, 1000, 800], resize=False, vis=True)
>>> res2 = zz.vision.paste(img, target, [200, 200, 1000, 800], resize=True, vis=True, alpha=255)
>>> poly -= zz.vision.poly2xyxy(poly)[:2]
>>> target = zz.vision.bbox(target, poly, color=(255, 0, 0), thickness=20)
>>> res3, poly3 = zz.vision.paste(img, target, [200, 200, 1000, 800], resize=False, poly=poly)
>>> poly3
array([[300. , 200. ],
[557.14285714, 200. ],
[900. , 628.57142857],
[557.14285714, 800. ],
[300. , 542.85714286]])
>>> res3 = zz.vision.bbox(res3, poly3)
>>> res4, poly4 = zz.vision.paste(img, target, [200, 200, 1000, 800], resize=True, poly=poly)
>>> poly4
array([[ 200. , 200. ],
[ 542.85714286, 200. ],
[1000. , 628.57142857],
[ 542.85714286, 800. ],
[ 200. , 542.85714286]])
>>> res4 = zz.vision.bbox(res4, poly4)
>>> res5, poly5 = zz.vision.paste(img, target, [200, 200, 1000, 800], resize=True, poly=poly, gaussian=501)
>>> res5 = zz.vision.bbox(res5, poly5)
Source code in zerohertzLib/vision/visual.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
text ¶
text(img: NDArray[uint8], box: list[int | float] | NDArray[DTypeLike], txt: str | list[str], color: tuple[int, int, int] = (0, 0, 0), vis: bool = False, fontsize: int = 100) -> NDArray[uint8]
Text 시각화
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img | NDArray[uint8] | 입력 image ( | required |
box | list[int | float] | NDArray[DTypeLike] | 문자열이 존재할 bbox ( | required |
txt | str | list[str] | Image에 추가할 문자열 | required |
color | tuple[int, int, int] | 문자의 색 | (0, 0, 0) |
vis | bool | 문자 영역의 시각화 여부 | False |
fontsize | int | 문자의 크기 | 100 |
Returns:
| Type | Description |
|---|---|
NDArray[uint8] | 시각화 결과 ( |
Examples:
Bbox:
>>> box = np.array([[100, 200], [100, 1000], [1200, 1000], [1200, 200]])
>>> box.shape
(4, 2)
>>> res1 = zz.vision.text(img, box, "먼지야")
>>> boxes = np.array([[250, 200, 100, 100], [600, 600, 800, 200], [900, 300, 300, 400]])
>>> boxes.shape
(3, 4)
>>> res2 = zz.vision.text(img, boxes, ["먼지야", "먼지야", "먼지야"], vis=True)



