Advertisement
dan-masek

Untitled

Dec 11th, 2016
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3.  
  4. img = cv2.imread('comics.jpg')
  5. imgrey = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  6. ret,thresh1 = cv2.threshold(imgrey,127,255,cv2.THRESH_BINARY_INV)
  7.  
  8. contours,heirarchy = cv2.findContours(thresh1,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
  9.  
  10. for contour in contours:
  11.   hull = cv2.convexHull(contour)
  12.   cv2.drawContours(imgrey,[hull],-1,0,-1)
  13.  
  14. ret,thresh1 = cv2.threshold(imgrey,127,255,cv2.THRESH_BINARY_INV)
  15. contours,heirarchy = cv2.findContours(thresh1,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
  16.  
  17. for contour in contours:
  18.   cv2.drawContours(img,[contour],-1,(0,255,0),3)
  19.  
  20. cv2.imwrite('threshold_image.png',img)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement