Home > OS >  Pytesseract not giving excpected resaults
Pytesseract not giving excpected resaults

Time:01-10

using pytesseract for image to text along with some basic image enhancing, Problem is that im getting very weird resaults. Pyton



import cv2
import pytesseract
import numpy as np
from PIL import Image
from PIL import ImageEnhance

filename = 'image3.png'
color_image = Image.open(filename)

# Enhance Color Level

curr_col = ImageEnhance.Color(color_image)
new_col = 5
img_colored = curr_col.enhance(new_col)
\#enhance sharpness
curr_col = ImageEnhance.Sharpness(color_image)
new_enh = 2
img_colored = curr_col.enhance(new_enh)

# Color level enhanced by a factor of 2.5

bw = img_colored.convert('L')
bw.save('BW_image.png')
img_colored.save('enchanc.png')

img1 = np.array(Image.open("BW_image.png"))
text = pytesseract.image_to_string(img1)

print(text)

This is image3.png and this is what i get printed in the console "Nam 65 can gala" image3.png

CodePudding user response:

From your code, you apply some enhancements on the image 'image3.png', but you open another image img1 and then pass it to pytesseract.

import cv2
import pytesseract
import numpy as np
from PIL import Image
from PIL import ImageEnhance

filename = 'image3.png'
color_image = Image.open(filename)

text = pytesseract.image_to_string(color_image)

print(text)

this code outputs: Profit: 68.0666 gold

  • Related