Created
December 9, 2019 17:52
-
-
Save fuwiak/780cb4abbe01aa5d1438269dfa0a3cfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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