Created
November 21, 2022 01:15
-
-
Save remoharsono/2518788e925663a5bf60fab02e6c079d to your computer and use it in GitHub Desktop.
Crop image and extract text from cropped image
This file contains hidden or 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
from PIL import Image | |
from pytesseract import pytesseract | |
path_to_tesseract = r'C:\Program Files\Tesseract-OCR\tesseract.exe' | |
pytesseract.tesseract_cmd = path_to_tesseract | |
img = Image.open("original_image.png") | |
# img.show() | |
box = (297, 10, 584, 50) | |
img2 = img.crop(box) | |
croppedImage = "cropped_image.png" | |
img2.save(croppedImage) | |
# img2.show() | |
img3 = Image.open(croppedImage) | |
text = pytesseract.image_to_string(img3) | |
print(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment