由于使用PyTesseract的背景色,无法从屏幕截图中读取文本

问题描述 投票:1回答:1

我正在尝试使用pytesseract从计算机/移动屏幕截图中提取和检测文本。它工作正常,但在这种情况下,由于绿色背景,未检测到按钮文字。

原始图像

Original Image

文本检测后的图像

Detected Text

这是我使用的代码:

d = pytesseract.image_to_data(img, output_type=Output.DICT)# img is an numpy nd array, i.e image read using OpenCV
n_boxes = len(d['level'])
for i in range(n_boxes):
    # eliminating blank characters
    if d['text'][i].strip() == '': continue
    else: print(d['text'][i])
    (x,y,w,h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
    cv2.rectangle(img, (x,y), (x+w, y+h), (0, 255, 0), 2)

plot_image(img)
python opencv computer-vision python-tesseract
1个回答
1
投票

尝试对图像进行二值化处理,使其变为黑白。对于这种用例,二值化/图像阈值化是一种常用的图像处理方法。

这些链接可能有帮助。

1. ImageThresholding-Opencv

2. Adaptive Thresholding

3. Text Binarization

© www.soinside.com 2019 - 2024. All rights reserved.