Skip to content

Commit a7f0329

Browse files
author
thugeyy
committed
Implement OCR Tool for Image-to-Text Conversion
1 parent 557c7f8 commit a7f0329

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytesseract
2+
from PIL import Image
3+
import os
4+
5+
def extract_text_from_image(image_path):
6+
"""Extracts text from an image file using Tesseract OCR."""
7+
try:
8+
# Open the image file
9+
with Image.open(image_path) as img:
10+
# Use pytesseract to do OCR on the image
11+
extracted_text = pytesseract.image_to_string(img)
12+
return extracted_text
13+
except Exception as e:
14+
print(f"Error processing the image: {e}")
15+
return None
16+
17+
def main():
18+
19+
image_path = input("Enter the path to the image file: ")
20+
21+
if not os.path.isfile(image_path):
22+
print("File does not exist. Please check the path and try again.")
23+
return
24+
text = extract_text_from_image(image_path)
25+
26+
if text:
27+
print("Extracted Text:")
28+
print(text)
29+
30+
if __name__ == "__main__":
31+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pillow==11.0.0
2+
pytesseract==0.3.13

0 commit comments

Comments
 (0)