我使用代码来定位文本框并在它们周围创建一个矩形。这使我可以围绕图像中的表格结构重建网格。
但是,即使文本框检测效果很好,如果我尝试定义每个矩形中存在的字符,pytesseract 也无法很好地识别它们并且无法找到原始文本。
这是我的 Python 代码:
import os
import cv2
import imutils
import argparse
import numpy as np
import pytesseract
# This only works if there's only one table on a page
# Important parameters:
# - morph_size
# - min_text_height_limit
# - max_text_height_limit
# - cell_threshold
# - min_columns
def pre_process_image(img, save_in_file, morph_size=(8, 8)):
# get rid of the color
pre = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
def img_estim(img, threshold=127):
is_dark = np.mean(img) < threshold
return True if is_dark else False
# …Run Code Online (Sandbox Code Playgroud)