Guest User

Untitled

a guest
Jul 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. [![enter image description here][2]][2]enter code here
  2. import cv2
  3. import pytesseract
  4. from PIL import Image
  5. import numpy as np
  6. # import bm3d
  7. img = cv2.imread('1_2_2.png')
  8. # img = cv2.medianBlur(img, 5)
  9. img = cv2.GaussianBlur(img,(13,13),0)
  10. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  11. # gray = cv2.medianBlur(, 5)
  12. # cv2.imshow("img", gray)
  13. # gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY |
  14. cv2.THRESH_OTSU)
  15. [1]
  16. v = np.median(gray)
  17. sigma = 0.33
  18. #---- apply automatic Canny edge detection using the computed median--
  19. --
  20. lower = int(max(0, (1.0 - sigma) * v))
  21. upper = int(min(255, (1.0 + sigma) * v))
  22. gray = cv2.Canny(img,lower,upper)
  23. # ret,gray = cv2.threshold(gray,110,255,cv2.THRESH_BINARY)
  24. kernel = np.ones((4,4),np.uint8)
  25. gray = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
  26. gray = cv2.dilate(gray,kernel,iterations = 1)
  27. # gray = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
  28. # gray = cv2.erode(gray,kernel,iterations = 1)
  29. gray = cv2.bitwise_not(gray)
  30. cv2.imshow("threshold", gray)
  31. cv2.waitKey(0)
  32. cv2.destroyAllWindows()
  33. # gray = cv2.medianBlur(gray, 3)
  34. text = pytesseract.image_to_string(gray)
  35. print(text)
Add Comment
Please, Sign In to add comment