Advertisement
Guest User

Untitled

a guest
Nov 24th, 2018
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import tesserocr
  2. from PIL import Image
  3. import pytesseract
  4. import matplotlib as plt
  5. import cv2
  6. import imutils
  7. import numpy as np
  8.  
  9. image = cv2.imread(r'c:\ahmed\ahmed.jpg')
  10. gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  11.  
  12. gray = cv2.bilateralFilter(gray,30,50,50)
  13. gray = cv2.GaussianBlur(gray,(5,5), 0)
  14. image = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
  15. cv2.THRESH_BINARY,11,2)
  16.  
  17. #gray = cv2.Canny(gray, 70, 200)
  18. #cv2.imshow("dilation", img_dilation)
  19.  
  20. cv2.imshow("gray", image)
  21.  
  22. #crop_img = gray[215:215+315, 783:783+684]
  23. #cv2.imshow("cropped", crop_img)
  24.  
  25. resize = imutils.resize(image, width = 460)
  26. cv2.imshow("resize", resize)
  27.  
  28. text = pytesseract.image_to_string(resize, lang='ara')
  29. print(text)
  30. with open(r"c:\ahmed\file.txt", "w", encoding="utf-8") as myfile:
  31. myfile.write(text)
  32. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement