Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions OCR Image-to-Text Conversion/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytesseract
from PIL import Image
import os

def extract_text_from_image(image_path):
"""Extracts text from an image file using Tesseract OCR."""
try:
# Open the image file
with Image.open(image_path) as img:
# Use pytesseract to do OCR on the image
extracted_text = pytesseract.image_to_string(img)
return extracted_text
except Exception as e:
print(f"Error processing the image: {e}")
return None

def main():

image_path = input("Enter the path to the image file: ")

if not os.path.isfile(image_path):
print("File does not exist. Please check the path and try again.")
return
text = extract_text_from_image(image_path)

if text:
print("Extracted Text:")
print(text)

if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions OCR Image-to-Text Conversion/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pillow==11.0.0
pytesseract==0.3.13
Loading