1 | initial version |
I don't know which one do you want. Unfortunately, never answered question.. Here is code:
import cv2
import numpy as np
# load the example image
image = cv2.imread("h2.jpg")
# pre-process the image by resizing it, converting it to
# graycale, blurring it, and computing an edge map
image = cv2.resize(image, (500, 500))
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blurred, 50, 200)
im,cnts,hierarchy = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[:15] #cnts = cnts[1:][:7]
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)
for c in cnts:
cv2.drawContours(image, [c], -1, (0,255,0), 2)
cv2.imshow('EDGED', edged)
cv2.imshow('DRAWN CONTOURS', image)
cv2.imshow('RETURNED IMAGE', im)
cv2.waitKey(0)