我正在尝试使用mss
和pytesseract
在python中创建一个实时的光学字符识别。
到目前为止,我已经能够捕捉到FPS稳定为30的整个屏幕。如果我想要捕捉500x500左右的较小区域,我已经能够获得100+ FPS。
然而,一旦我加入这行代码,text = pytesseract.image_to_string(img)
,boom 0.8FPS。有没有办法优化我的代码以获得更好的FPS?此外,该代码能够检测文本,只是速度非常慢。
from mss import mss
import cv2
import numpy as np
from time import time
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'C:\\Users\\Vamsi\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe'
with mss() as sct:
# Part of the screen to capture
monitor = {"top": 200, "left": 200, "width": 500, "height": 500}
while "Screen capturing":
begin_time = time()
# Get raw pixels from the screen, save it to a Numpy array
img = np.array(sct.grab(monitor))
# Finds text from the images
text = pytesseract.image_to_string(img)
# Display the picture
cv2.imshow("Screen Capture", img)
# Display FPS
print('FPS {}'.format(1 / (time() - begin_time)))
# Press "q" to quit
if cv2.waitKey(25) & 0xFF == ord("q"):
cv2.destroyAllWindows()
break
发布于 2021-02-24 00:58:33
pytesseract“默认”效率不高,因为它包装了tesseract可执行文件,它将临时文件保存到磁盘等。如果你对性能很认真,你需要直接使用tesseract API (例如,通过tesserocr或通过creating custom API wrapper)
https://stackoverflow.com/questions/66334737
复制相似问题