Advertisement
Guest User

Untitled

a guest
Jul 15th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img = cv2.imread('sofsk.png',0)
  5.  
  6. ############### APPLY INVERSION HERE #########################
  7.  
  8. img = cv2.bitwise_not(img)
  9.  
  10. ###############################################
  11. size = np.size(img)
  12. skel = np.zeros(img.shape,np.uint8)
  13.  
  14. ret,img = cv2.threshold(img,127,255,0)
  15. element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
  16. done = False
  17.  
  18. while( not done):
  19.     eroded = cv2.erode(img,element)
  20.     temp = cv2.dilate(eroded,element)
  21.     temp = cv2.subtract(img,temp)
  22.     skel = cv2.bitwise_or(skel,temp)
  23.     img = eroded.copy()
  24.  
  25.     zeros = size - cv2.countNonZero(img)
  26.     if zeros==size:
  27.         done = True
  28.  
  29. cv2.imshow("skel",skel)
  30. cv2.waitKey(0)
  31. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement