Ask Your Question

Revision history [back]

Unable to draw contours using this code. Please help

import cv2 import numpy as np import matplotlib.pyplot as plt

image = cv2.imread('C:\Users\suman\Desktop\shapes.jpg') cv2.imshow('Input image', image) cv2.waitKey(0)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

edged= cv2.Canny(gray, 30,200) cv2.imshow('Canny Edges', edged) cv2.waitKey(0)

image, contours, heirarchy = cv2.findContours(edged, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) cv2.imshow('Canny edges after countouring', edged) cv2.waitKey(0)

print ("Number of Contours found =" + str(len(contours)))

cv2.drawContours(image, contours, -1, (0,255,0),3) cv2.imshow('Contours', image) cv2.waitKey(0) image description