28 lines
824 B
Python
28 lines
824 B
Python
import cv2
|
|
import numpy as np
|
|
|
|
from cv_analysis.utils.common import find_contours
|
|
|
|
|
|
def detect_large_coherent_structures(image: np.array):
|
|
"""Detects large coherent structures on an image.
|
|
Expects an image with binary color space (e.g. threshold applied).
|
|
|
|
Returns:
|
|
contours
|
|
|
|
References:
|
|
https://stackoverflow.com/questions/60259169/how-to-group-nearby-contours-in-opencv-python-zebra-crossing-detection
|
|
"""
|
|
assert len(image.shape) == 2
|
|
|
|
dilate_kernel = cv2.getStructuringElement(cv2.MORPH_OPEN, (5, 5))
|
|
dilate = cv2.dilate(image, dilate_kernel, iterations=4)
|
|
|
|
close_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (20, 20))
|
|
close = cv2.morphologyEx(dilate, cv2.MORPH_CLOSE, close_kernel, iterations=1)
|
|
|
|
contours, _ = find_contours(close)
|
|
|
|
return contours
|