import sys import pytesseract from PIL import Image def ocr_image_to_text(image_path): try: # Open the image file image = Image.open(image_path) # Perform OCR on the image ocr_result = pytesseract.image_to_data(image, output_type=pytesseract.Output.DICT) # Extract and print the text portion text = [word for word in ocr_result['text'] if word.strip() != ""] print(" ".join(text)) except Exception as e: print(f"Error: {e}") if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: python ocr_to_text.py ") else: image_path = sys.argv[1] ocr_image_to_text(image_path)