Matthias Bisping 77f85e9de1 Refactoring
Various
2023-01-09 17:22:01 +01:00

40 lines
871 B
Python

import cv2
from cv_analysis.utils import copy_and_normalize_channels
def draw_contours(image, contours):
image = copy_and_normalize_channels(image)
for contour in contours:
cv2.drawContours(image, contour, -1, (0, 255, 0), 4)
return image
def draw_rectangles(image, rectangles, color=None, annotate=False):
def annotate_rect(x, y, w, h):
cv2.putText(
image,
"+",
(x + (w // 2) - 12, y + (h // 2) + 9),
cv2.FONT_HERSHEY_SIMPLEX,
1,
(0, 255, 0),
2,
)
image = copy_and_normalize_channels(image)
if not color:
color = (0, 255, 0)
for rect in rectangles:
x, y, w, h = rect
cv2.rectangle(image, (x, y), (x + w, y + h), color, 2)
if annotate:
annotate_rect(x, y, w, h)
return image