Skip to content

Instantly share code, notes, and snippets.

@saurabhpal97
Created March 23, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saurabhpal97/0702efd95fb378a7913b230a7957ce8a to your computer and use it in GitHub Desktop.
Save saurabhpal97/0702efd95fb378a7913b230a7957ce8a to your computer and use it in GitHub Desktop.
#importing the required libraries
import numpy as np
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
image = cv2.imread('shapes.png')
#converting RGB image to Binary
gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray_image,127,255,0)
#calculate the contours from binary image
im,contours,hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
with_contours = cv2.drawContours(image,contours,-1,(0,255,0),3)
plt.imshow(with_contours)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment