-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocr_image.py
More file actions
24 lines (23 loc) · 775 Bytes
/
ocr_image.py
File metadata and controls
24 lines (23 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Image to Text OCR
created and published by atrx07
Usage: python ocr_image.py /path/to/image.jpg
Optional: install pytesseract and tesseract engine for best results.
If pytesseract is not installed, the script prints a helpful message.
Requires (optional): pytesseract, pillow
"""
import sys
try:
from PIL import Image
import pytesseract
except Exception as e:
print("Optional dependency missing. For OCR install: pip install pillow pytesseract and system tesseract engine.")
sys.exit(0)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python ocr_image.py /path/to/image")
else:
img = Image.open(sys.argv[1])
text = pytesseract.image_to_string(img)
print("---- OCR OUTPUT ----")
print(text)