Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [![enter image description here][2]][2]enter code here
- import cv2
- import pytesseract
- from PIL import Image
- import numpy as np
- # import bm3d
- img = cv2.imread('1_2_2.png')
- # img = cv2.medianBlur(img, 5)
- img = cv2.GaussianBlur(img,(13,13),0)
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- # gray = cv2.medianBlur(, 5)
- # cv2.imshow("img", gray)
- # gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY |
- cv2.THRESH_OTSU)
- [1]
- v = np.median(gray)
- sigma = 0.33
- #---- apply automatic Canny edge detection using the computed median--
- --
- lower = int(max(0, (1.0 - sigma) * v))
- upper = int(min(255, (1.0 + sigma) * v))
- gray = cv2.Canny(img,lower,upper)
- # ret,gray = cv2.threshold(gray,110,255,cv2.THRESH_BINARY)
- kernel = np.ones((4,4),np.uint8)
- gray = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
- gray = cv2.dilate(gray,kernel,iterations = 1)
- # gray = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
- # gray = cv2.erode(gray,kernel,iterations = 1)
- gray = cv2.bitwise_not(gray)
- cv2.imshow("threshold", gray)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
- # gray = cv2.medianBlur(gray, 3)
- text = pytesseract.image_to_string(gray)
- print(text)
Add Comment
Please, Sign In to add comment