diff --git a/OCR Image-to-Text Conversion/main.py b/OCR Image-to-Text Conversion/main.py new file mode 100644 index 0000000..e475973 --- /dev/null +++ b/OCR Image-to-Text Conversion/main.py @@ -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() diff --git a/OCR Image-to-Text Conversion/requirements.txt b/OCR Image-to-Text Conversion/requirements.txt new file mode 100644 index 0000000..f7fcb04 --- /dev/null +++ b/OCR Image-to-Text Conversion/requirements.txt @@ -0,0 +1,2 @@ +pillow==11.0.0 +pytesseract==0.3.13 \ No newline at end of file