图像到文本-Pytesseract与Windows上的数字作斗争 [英] Image to Text - Pytesseract struggles with digits on windows
问题描述
我正在尝试为ML项目实时预处理游戏框架.我想从框架中提取数字,所以我选择了Pytesseract,因为它在文本上看起来相当不错.虽然,无论我做的文字多么清晰,它都无法正确阅读.我的代码如下:
I'm trying to preprocess frames of a game in real-time for a ML project. I want to extract numbers from the frame, so I chose Pytesseract, since it looked quite good with text. Though, no matter how clear I make the text, it won't read it correctly. My code looks like this:
section = process_screen(screen_image)[1]
pixels = rgb_to_bw(section) #Makes the image grayscale
pixels[pixels < 200] = 0 #Makes all non-white pixels black
tess.image_to_string(pixels)
=> 'ye ml)'
当我未指定我想要数字时,充其量它最多会输出"ye ml)",而当我输入数字时,它什么也不会输出.
At best it outputs "ye ml)" when I don't specify I want digits, and when I do, it outputs nothing at all.
未经处理的游戏图像如下所示:
The non-processed game image looks like so:
像素"图像如下所示:
The "pixels" image looks like so :
感谢Alex Alex,我反转了图像,并得到了
Thanks to Alex Alex, I inverted the image, and got this
得到"2710",虽然更好,但仍不完美.
And got "2710", which is better, but still not perfect.
推荐答案
在识别之前必须反转图像.
You must invert the image before recognition.
这篇关于图像到文本-Pytesseract与Windows上的数字作斗争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!