给定可以在任何语言或书写系统中输入的图像,如何检测图片中的文本所使用的脚本?
任何基于Python或基于Tesseract OCR的解决方案都将不胜感激.
请注意,这里的脚本意味着为相应的语言(分别为英语、俄语、印地语等)编写拉丁文、西里尔语、Devanagari等系统。
发布于 2021-12-02 11:54:56
Pre-requisites:
安装Tesseract:sudo apt install tesseract-ocr tesseract-ocr-all
pip install pytesseractScript-Detection:
import pytesseract
import re
def detect_image_lang(img_path):
try:
osd = pytesseract.image_to_osd(img_path)
script = re.search("Script: ([a-zA-Z]+)\n", osd).group(1)
conf = re.search("Script confidence: (\d+\.?(\d+)?)", osd).group(1)
return script, float(conf)
except e:
return None, 0.0
script_name, confidence = detect_image_lang("image.png")Language-Detection:
执行OCR (using Tesseract)后,传递文本through langdetect library (或任何其他库)。
https://stackoverflow.com/questions/70198974
复制相似问题