0

What I tried so far. it's working fine most of image which is text black and background is white.

from PIL import Image
import pytesseract
import nltk
import cv2

imageName = "p9.png"
img = cv2.imread(imageName,cv2.IMREAD_COLOR) #Open the image from which charectors has to be recognized
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #convert to grey to reduce detials
gray = cv2.bilateralFilter(gray, 11, 17, 17) #Blur to reduce noise
original = pytesseract.image_to_string(gray, config='')
print (original)

but below image I do not give right text.

enter image description here

Output:

REMIUM OKING OIL

KETTLE-RENDERED 9s MADE FROM POR siren!

fatworks €)

NET WT. 4 02 (3966)

how to resolve this issue.

Community
  • 1
  • 1
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73

1 Answers1

0

What I meant is

imageName = "p9.png"
img = cv2.imread(imageName,cv2.IMREAD_COLOR) #Open the image from which charectors has to be recognized
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #convert to grey to reduce detials
gray = cv2.bilateralFilter(gray, 11, 17, 17) #Blur to reduce noise
img = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,71,2)
#img = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
            cv2.THRESH_BINARY,11,2)
original = pytesseract.image_to_string(img, config='')

Play around with parameters of this function to find what works for you best cv2.adaptiveThreshold(src, maxValue, adaptiveMethod, thresholdType, blockSize, C[, dst]).

I also keep here a link to original tutorial: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_thresholding/py_thresholding.html

Lukashou-AGH
  • 125
  • 10