python-3.x - 从图像中自动检测语言以提取 OCR 字符

标签 python-3.x opencv image-processing tensorflow python-tesseract

我正在使用上传图像的 python 构建一个软件。该软件将使用 tesseract ocr 提取文本。

但我希望我的软件能够自动检测图像中的语言并提取检测到的文本。

请给我一些建议,我也准备好进行机器学习,但我无法确定该过程的完美管道。

提前致谢。

最佳答案

过程复杂,你需要做的是

  1. 从 lang=eng 格式的图像中提取文本
  2. 将该文本传递给 langdetect 它是 google 自动语言检测库
  3. 再次在 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/

相关文章:

python - 字典在迭代期间改变大小

python - 根据单独的列将前几行聚合到列表中

opencv - 确定两个 360x180 等距柱状全景图像之间的相机旋转

c++ - 14 段显示和 Tesseract OCR with OpenCV

java - 透视变换——OpenCV显示镜像

c# - 系统参数异常 : Parameter is not valid

python - 如何正确地从带有空行的 CSV 导入字典?

python - 在执行操作的单独子数组中获取 numpy 子数组的结果,而不使用 for 循环

python - 在python中有效地将颜色转换为透明度

java - 提取哪个 channel - ImageJ