Skip to content

Instantly share code, notes, and snippets.

@fuwiak
Created December 9, 2019 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fuwiak/780cb4abbe01aa5d1438269dfa0a3cfc to your computer and use it in GitHub Desktop.
Save fuwiak/780cb4abbe01aa5d1438269dfa0a3cfc to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
import imutils
import os
import pytesseract
from PIL import Image
from pytesseract import image_to_string
# image = cv2.imread("bill1.png")
# ratio = image.shape[0] / 500.0
# orig = image.copy()
# image = imutils.resize(image, height = 500)
# load the example image and convert it to grayscale
# "a.png"---> change this name
image = cv2.imread("a.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# write the grayscale image to disk as a temporary file so we can
# apply OCR to it
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename, gray)
text = pytesseract.image_to_string(Image.open(filename))
os.remove(filename)
print(text)
# show the output images
cv2.imshow("Image", image)
cv2.imshow("Output", gray)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment