我有这个代码简单代码
import pytesseract as pt
from PIL import Image
pt.pytesseract.tesseract_cmd = 'D:\\tesseract\\tesseract.exe'
def extract_text_from_image(image_path):
img = Image.open(image_path)
text = pt.image_to_string(img)
return text
image_path = 'D:\\script\\materials\\screenshot.jpg'
text = extract_text_from_image(image_path)
print(text)
exe路径正确,截图路径正确,有图像 为什么它无法识别文本,即使它不是不可读的东西
我尝试使用 ImageEnhance、阈值并转换为灰度 我也尝试使用 .png 格式,但仍然不起作用 为什么会这样?
通过将页面分割模式 6 传递给“image_to_string”方法,我已成功从您的图像中读取文本。
pt.image_to_string(img, config="--psm 6")
您可以在此处了解有关不同细分模式及其作用的更多信息: https://pyimagesearch.com/2021/11/15/tesseract-page-segmentation-modes-psms-explained-how-to-improve-your-ocr-accuracy/