Segmenting wedges from a Binary image with opencv

Viewed 96

I have a B/W image, how do I go about identifying the wedges in the input image as shown in the marked image?

Input image

Input image

Wedges marked on image

Wedges marked on image

1 Answers

enter image description here

You can use findContours() to detect bounding boxes and contours

import cv2
import numpy as np

image = cv2.imread('2.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Find contours
cnts = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

for c in cnts:
    cv2.drawContours(image,[c], 0, (0,255,0), 2)

cv2.imshow('image', image)
cv2.imwrite('image.png', image)
cv2.waitKey(0)
Related