Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tesserocr
- from PIL import Image
- import pytesseract
- import matplotlib as plt
- import cv2
- import imutils
- import numpy as np
- image = cv2.imread(r'c:\ahmed\ahmed.jpg')
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- gray = cv2.bilateralFilter(gray,30,50,50)
- gray = cv2.GaussianBlur(gray,(5,5), 0)
- image = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
- cv2.THRESH_BINARY,11,2)
- #gray = cv2.Canny(gray, 70, 200)
- #cv2.imshow("dilation", img_dilation)
- cv2.imshow("gray", image)
- #crop_img = gray[215:215+315, 783:783+684]
- #cv2.imshow("cropped", crop_img)
- resize = imutils.resize(image, width = 460)
- cv2.imshow("resize", resize)
- text = pytesseract.image_to_string(resize, lang='ara')
- print(text)
- with open(r"c:\ahmed\file.txt", "w", encoding="utf-8") as myfile:
- myfile.write(text)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement