Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is code:

import cv2
import numpy as np

image = cv2.imread('sunflower.png')

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (23, 23), 0)
cv2.imshow("blurred", blurred)

canny = cv2.Canny(blurred, 30, 30)
cnts, _ = cv2.findContours(canny.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

print(f"Contours in the image, %d" % (len(cnts)))

shape = image.copy()

cv2.drawContours(shape, cnts, -1, (0, 255, 0), 2)

cv2.imwrite('{}.png'.format('sunflower'), shape)

cv2.imshow("Edges", shape)
cv2.waitKey(0)

Output: image description