Unable to read image text with python tesseract and OpenCV help me

29 views Asked by At

enter image description hereimport pytesseract from PIL import Image, ImageEnhance, ImageFilter

Function to enhance image

def enhance_img(filename): # Open the image im = Image.open(filename)

# Enhance image and save under a new name
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')

# Save the enhanced image with a new filename
newfilename = filename[:-4] + '_enhanced.png'
im.save(newfilename)

Path to your image file

image_path = "C:/Users/ws_htu1000/OneDrive - Hoonartek/Pictures/ram/captcha_image_processed.png"

Enhance the image

enhance_img(image_path)

Open the enhanced image file

enhanced_image_path = "C:/Users/ws_htu1000/OneDrive - Hoonartek/Pictures/ram/captcha_image_processed_enhanced.png" img = Image.open(enhanced_image_path)

Use pytesseract to do OCR on the enhanced image

text = pytesseract.image_to_string(img)

Print the extracted text

print("Extracted Text:", text)

this image i want to convert

import pytesseract from PIL import Image, ImageEnhance, ImageFilter

Function to enhance image

def enhance_img(filename): # Open the image im = Image.open(filename)

# Enhance image and save under a new name
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')

# Save the enhanced image with a new filename
newfilename = filename[:-4] + '_enhanced.png'
im.save(newfilename)

Path to your image file

image_path = "C:/Users/ws_htu1000/OneDrive - Hoonartek/Pictures/ram/captcha_image_processed.png"

Enhance the image

enhance_img(image_path)

Open the enhanced image file

enhanced_image_path = "C:/Users/ws_htu1000/OneDrive - Hoonartek/Pictures/ram/captcha_image_processed_enhanced.png" img = Image.open(enhanced_image_path)

Use pytesseract to do OCR on the enhanced image

text = pytesseract.image_to_string(img)

Print the extracted text

print("Extracted Text:", text)

0

There are 0 answers