0
我想要做的就是用pyautogui制作一个数字的截图,并将数字转换为带有pytesseract的字符串。代码: 进口pyautogui 进口时间 进口PIL 从PIL进口图片 进口pytesseractPytesseract不接受pyautogui截图,Windows,Python 3.6
pytesseract.pytesseract.tesseract_cmd = 'C://Program Files (x86)//Tesseract-OCR//tesseract'
# Create image
time.sleep(5)
image = pyautogui.screenshot('projects/output.png', region=(1608, 314, 57, 41))
# Resize image
basewidth = 2000
img = Image.open('projects/output.png')
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS)
img.save('projects/output.png')
col = Image.open('projects/output.png')
gray = col.convert('L')
bw = gray.point(lambda x: 0 if x<128 else 255, '1')
bw.save('projects/output.png')
# Image to string
screen = Image.open('projects/output.png')
print(pytesseract.image_to_string(screen, config='tessedit_char_whitelist='))
现在看来,pytesseract不接受截图pyautogui创建。代码运行良好,没有问题,但打印出一个空字符串。如果我在paint中创建一个图像,并将其保存为'output.png'到正确的文件夹,就像截图一样,它确实有效。
Image output after resize and adjustments
任何人有一个想法,我失去了一些东西?