我正在使用上传图像的 python 构建一个软件。该软件将使用 tesseract ocr 提取文本。
但我希望我的软件能够自动检测图像中的语言并提取检测到的文本。
请给我一些建议,我也准备好进行机器学习,但我无法确定该过程的完美管道。
提前致谢。
最佳答案
过程复杂,你需要做的是
- 从 lang=eng 格式的图像中提取文本
- 将该文本传递给 langdetect 它是 google 自动语言检测库
- 再次在 tesseract 中使用该语言准确提取文本
或者
您可以对每种语言使用 switch case,并将示例文本传递给 langdetect 以获得哪种语言正确的概率。
import pytesseract
pytesseract.pytesseract.tesseract_cmd =
'<full_path_to_your_tesseract_executable>'
# Include the above line, if you don't have tesseract executable in your path
# Example tesseract_cmd: 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'
print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='eng'))
sample_text = pytesseract.image_to_string(Image.open('image.jpg'), lang='eng')
from langdetect import detect_langs detect_langs(sample_text)
关于python-3.x - 从图像中自动检测语言以提取 OCR 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47688813/