Updating tiff image patch
This commit is contained in:
@@ -17,6 +17,7 @@ import matplotlib.pyplot as plt
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import random
|
||||
from shapely.geometry import LineString
|
||||
|
||||
from src.utils.image import Image
|
||||
|
||||
@@ -75,7 +76,12 @@ def draw_annotations(img, labels, alpha=0.4, draw_bbox_for_poly=True):
|
||||
# img: BGR numpy array
|
||||
overlay = img.copy()
|
||||
h, w = img.shape[:2]
|
||||
for cls, coords in labels:
|
||||
for line in labels:
|
||||
if isinstance(line, str):
|
||||
cls, coords = parse_label_line(line)
|
||||
if isinstance(line, tuple):
|
||||
cls, coords = line
|
||||
|
||||
if not coords:
|
||||
continue
|
||||
# polygon case (>=6 coordinates)
|
||||
@@ -83,9 +89,16 @@ def draw_annotations(img, labels, alpha=0.4, draw_bbox_for_poly=True):
|
||||
color = random_color_for_class(cls)
|
||||
|
||||
x1, y1, x2, y2 = yolo_bbox_to_xyxy(coords[:4], w, h)
|
||||
print(x1, y1, x2, y2)
|
||||
cv2.rectangle(img, (x1, y1), (x2, y2), color, 1)
|
||||
|
||||
pts = poly_to_pts(coords[4:], w, h)
|
||||
line = LineString(pts)
|
||||
# Buffer distance in pixels
|
||||
buffered = line.buffer(3, cap_style=2, join_style=2)
|
||||
coords = np.array(buffered.exterior.coords, dtype=np.int32)
|
||||
cv2.fillPoly(overlay, [coords], color=(255, 255, 255))
|
||||
|
||||
# fill on overlay
|
||||
cv2.fillPoly(overlay, [pts], color)
|
||||
# outline on base image
|
||||
|
||||
Reference in New Issue
Block a user