pytesseract image_to_string 函数根本不准确 [英] pytesseract image_to_string function not accurate at all
本文介绍了pytesseract image_to_string 函数根本不准确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码
for index, img in enumerate(data): # data is list of base64 decoded strings
b64 = base64.b64decode(bytes(img[22:], encoding='utf-8'))
raw = BytesIO(b64)
im = Image.open(raw).convert('LA')
pixels = im.load()
width, height = im.size
for x in range(width):
for y in range(height):
if pixels[x, y][0] > 100: pixels[x, y] = (255, 255)
else: pixels[x, y] = (0, 255)
print(pytesseract.image_to_string(im, config='tessedit_char_whitelist=1234567890plus?'))
我的图片:
输出:Te Ys
我可以做些什么来使它更好,我尝试在配置中使用从 0 到 13 的每个 psm 和 -c 标志
Output:
Te Ys
What I can do to make this better, I tried to use every psm from 0 to 13 and -c flag in config
推荐答案
这段代码对我来说效果很好,但没有检测到空格.
This code worked fine for me but spaces were not detected.
img = ~cv2.imread("18.png",0)
rows,cols = img.shape[:2]
# M = np.float32([[1,0,25],[0,1,15]])
# img = cv2.warpAffine(img,M,(cols*2,rows*2),borderValue=(255,255,255))
custom_oem_psm_config = r'--oem 3 --psm 3 -c tessedit_char_whitelist="1234567890plus?"'# -c preserve_interword_spaces=1'
print(pytesseract.image_to_string(img,config=custom_oem_psm_config))
输出:
18plus16?
这篇关于pytesseract image_to_string 函数根本不准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文