Skip to content

Instantly share code, notes, and snippets.

@kivantium
Created April 1, 2018 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kivantium/7a45af7743aede244011def021d15e0e to your computer and use it in GitHub Desktop.
Save kivantium/7a45af7743aede244011def021d15e0e to your computer and use it in GitHub Desktop.
import cv2
image = cv2.imread("test.png")
imgray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
image2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
result = cv2.drawContours(image, contours, -1, (0,255,0), 5)
cv2.imwrite("result.png", result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment