daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2
  2. import numpy as np
  3.  
  4. image = cv2.imread('images/opencv_inv.png', 0)
  5.  
  6. cv2.imshow('Original', image)
  7. cv2.waitKey(0)
  8.  
  9. # Let's define our kernel size
  10. kernel = np.ones((5,5), np.uint8)
  11.  
  12. # Now we erode
  13. erosion = cv2.erode(image, kernel, iterations = 1)
  14. cv2.imshow('Erosion', erosion)
  15. cv2.waitKey(0)
  16.  
  17. #
  18. dilation = cv2.dilate(image, kernel, iterations = 1)
  19. cv2.imshow('Dilation', dilation)
  20. cv2.waitKey(0)
  21.  
  22. # Opening - Good for removing noise
  23. opening = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
  24. cv2.imshow('Opening', opening)
  25. cv2.waitKey(0)
  26.  
  27. # Closing - Good for removing noise
  28. closing = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel)
  29. cv2.imshow('Closing', closing)
  30. cv2.waitKey(0)
  31.  
  32.  
  33. cv2.destroyAllWindows()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top