我正在为视频游戏创建一个机器人,我必须阅读屏幕上显示的一些信息。鉴于信息总是在同一个位置,我可以截图并将图片裁剪到正确的位置。
90% 的时间,识别是完美的,但有时它会返回一些看起来完全随机的东西(见下面的例子)。
我尝试将图片变成黑白但没有成功,并尝试更改 pytesseract 配置(config = ("-l fra --oem 1 --psm 6"))
def readScreenPart(x,y,w,h):
monitor = {"top": y, "left": x, "width": w, "height": h}
output = "monitor.png"
with mss.mss() as sct:
sct_img = sct.grab(monitor)
mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
img = cv2.imread("monitor.png")
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite("result.png", img)
config = ("-l fra --oem 1 --psm 6")
return pytesseract.image_to_string(img,config=config)
示例:此图片生成一个错误,它返回字符串“IRPMV/LEIILK”
另一个图像
现在我不知道问题出在哪里,因为它不仅仅是一个错误的字符,而是一个完全随机的结果..
谢谢你的帮助







