python-3.x - 使用 Python3 Pytesseract 进行实时屏幕监控

标签 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()

最佳答案

我对 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

关于python-3.x - 使用 Python3 Pytesseract 进行实时屏幕监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54795273/

相关文章:

c++ - 使用 OpenCV 最小化方程中的矩阵

c++ - 在 OpenCV 中循环遍历 16 位 Mat 像素的有效方法

java - android NDK——将C++方法转换为java方法

python - 如何才能发送超过 280 个字符的推文?因此,如果字符串 > 280,则打印前 280 个字符,然后在该线程中使用其余字符再次发推文

python - "_tkinter.TclError: image "pyimage4 "doesn' t 存在”

python - 从行列表(稀疏向量)创建稀疏矩阵

C#.Net - 线程在一个循环中抓取相同的文件

python - 为什么dict键支持列表减法而不支持元组减法?

forms - 通过字段识别和光学字符识别 (OCR) 在预定义表格上进行手写数据输入自动化

python - PDF读取错误: File has not been decrypted