【问题标题】:how to get text from handwriting image in python如何从python中的手写图像中获取文本
【发布时间】:2022-01-16 15:22:00
【问题描述】:

图片:

图像是手写的文本行,这是提取文本的一些内容,但与图像中的预期不同

代码是

import cv2

img = cv2.imread("a.jpg")
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img = cv2.resize(img,(6000,100))

_, result1 = cv2.threshold(img,100,255,cv2.THRESH_BINARY)
_, result2 = cv2.threshold(img,100,255,cv2.THRESH_BINARY_INV)

adaptive_result1 = cv2.adaptiveThreshold(result1,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,199,5)
adaptive_result2 = cv2.adaptiveThreshold(result1,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,199,5)
adaptive_result3 = cv2.adaptiveThreshold(result2,100,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,199,5)
adaptive_result4 = cv2.adaptiveThreshold(result2,256,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,999,1)
# cv2.imshow("title",result)
# cv2.waitKey(0)
import pytesseract
from PIL import Image
from pytesseract import Output
configs = r'--psm 6 --oem 3'
pytesseract.pytesseract.tesseract_cmd =r'C:/Users/ASUS/OneDrive/Desktop/ubuntu file/tesseract.exe'

data = pytesseract.image_to_data(img, config=configs, output_type=Output.DICT)
print(*data['text'])
data = pytesseract.image_to_data(result2, config=configs, output_type=Output.DICT)
print(*data['text'])
data = pytesseract.image_to_data(adaptive_result3, config=configs, output_type=Output.DICT)
print(*data['text'])
data = pytesseract.image_to_data(adaptive_result4, config=configs, output_type=Output.DICT)
print(*data['text'])
# data = pytesseract.image_to_data(img, config=configs, output_type=Output.DICT)
# print(*data['text'])
# print(data.keys())

输出

buttered off before. there, twinkling like new Yar sytemy, hung cuter of tempting Uwitationx they beaged hi to contre the extera

【问题讨论】:

    标签: python opencv image-processing tesseract python-tesseract


    【解决方案1】:

    阈值可以更改,可以增加图像的结果,其余部分在 tesseract 上,因此无法更改图像的效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      相关资源
      最近更新 更多