Issue
I am trying to detect the text from the images but fail due to some unknown reasons.
import pytesseract as pt
from PIL import Image
import re
image = Image.open('sample.jpg')
custom_config = r'--oem 3 --psm 7 outbase digits'
number = pt.image_to_string(image, config=custom_config)
print('Number: ', number)
Number: 0 50 100 200 250 # This is the output that I am getting.
Expected --> 0,0,0,0,0,1,0,8
Solution
OCR using tesseract on crude/raw image inputs might not give you expected result. For the given image, a somewhat better result can be obtained using grayscale conversion followed by thresholding operation
To perform the conversion and thresholding operation you may use ImageMagick as follows:
$ convert input_image.jpg -colorspace gray grayscale_image.jpg
$ convert grayscale_image.jpg -threshold 45% thresholded_image.jpg
$ convert thresholded_image.jpg -morphology Dilate Rectangle:4,3 dilated_binary.jpg
$ python run_tesseract.py
00000109
A more robust approach to OCR is via training the tesseract engine discussed here
Answered By - vyi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.