Skip to content

Instantly share code, notes, and snippets.

@DIYer22
DIYer22 / get_max_inscribed_circle.py
Last active July 16, 2024 04:58
Get the maximum/largest inscribed circle inside mask/polygon/contours based on cv2. Support non-convex/hollow shape.
import cv2
import numpy as np
def get_test_mask():
# Create an image
r = 100
mask = np.zeros((4 * r, 4 * r), dtype=np.uint8)
# Create a sequence of points to make a contour
vert = [None] * 6
vert[0] = (3 * r // 2, int(1.34 * r))