使用Python3 Pytesseract进行实时屏幕监控

时间:2019-02-20 21:08:47

标签: python-3.x opencv ocr python-tesseract

我正在Windows 10上的python3项目中工作,我想知道是否有人知道通过pytesseract传递opencv屏幕抓取?如果没有,您还有其他OCR吗?

这是opencv屏幕抓取的代码:

import numpy as np
from PIL import ImageGrab
import cv2



while True:
    screen =  np.array(ImageGrab.grab(bbox=(0,40,800,640)))
    cv2.imshow('window', cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY))
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()

1 个答案:

答案 0 :(得分:2)

我对pytesseract知之甚少,但这可能会让您入门:

#!/usr/bin/env python3

import numpy as np
from PIL import ImageGrab
import pytesseract
from PIL import Image, ImageEnhance, ImageFilter
from textblob import TextBlob

# Grab some screen
screen =  ImageGrab.grab(bbox=(0,0,800,640))
# Make greyscale
w = screen.convert('L')

# Save so we can see what we grabbed
w.save('grabbed.png')

text = pytesseract.image_to_string(w)
correctedText = TextBlob(text).correct()

print(correctedText)

从这次抢夺中:

enter image description here

我知道了

@ Terminal Shell Edit View Window Help

The writing is on the wall