gvashist/ImageMapping
0
1import pytesseract2from PIL import Image3 4 5 6# Set the path to the Tesseract OCR executable (Windows only)7# pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'8 9 10 11def extract_text_from_image(image_path):12 try:13 # Open the image using PIL (Python Imaging Library)14 image = Image.open(image_path)15 16 17 18 # Perform OCR on the image to extract text19 text = pytesseract.image_to_string(image)20 21 22 23 return text.strip()24 except Exception as e:25 print(f"Error: {e}")26 return None27 28 29 30# Replace 'path/to/your/image.jpg' with the actual path to your image31image_path = '/doctor_glucosmeter_patient_hand-1200x628-FACEBOOK-1200x628.jpg'32extracted_text = extract_text_from_image(image_path)33 34 35 36if extracted_text:37 print("Extracted Text:")38 print(extracted_text)39else:40 print("No text found in the image.")