跳至內容。

Tesseract 訓練用字型

Tesseract 訓練可以使用由文字產生的影像,這些文字是用一系列字型渲染的。這些字型必須在執行訓練程序的主機上可用。

用於訓練 3.05 版 OCR 引擎和 4.0.0 版中傳統 OCR 引擎的字型定義在 training/language-specific.sh 中。

langdata/font_properties 中列出了更多字型。如果您將字型新增至第一個檔案(或透過命令列參數明確指定它們),您也必須將它們新增至第二個檔案。

用於訓練 4.0.0 版中 LSTM OCR 引擎的字型定義在 langdata_lstm repo 中的 <lang>/okfonts.txt 檔案中。

尋找字型

若要尋找已安裝在您系統上且將渲染給定訓練文字的字型,您可以使用以下命令(變更語言代碼和目錄位置以符合您的設定)。fontslist.txt 將提供可在 training/language-specific.sh 中使用的文字。

text2image --find_fonts \
--fonts_dir /usr/share/fonts \
--text ./langdata/eng/eng.training_text \
--min_coverage .9  \
--outputbase ./langdata/eng/eng \
|& grep raw \
 | sed -e 's/ :.*/@ \\/g' \
 | sed -e "s/^/  '/" \
 | sed -e "s/@/'/g" >./langdata/eng/fontslist.txt

上述方法不適用於 Fraktur 字型,它也會識別所有拉丁字型。請檢閱產生的影像並選擇適當的字型。

字型安裝

Debian

在 Debian GNU Linux 和類似的發行版(Linux Mint、Ubuntu 等)上,可以這樣安裝所需的字型

# AMHARIC_FONTS (todo)
# ANCIENT_GREEK_FONTS (todo)
# ARABIC_FONTS (todo)
# ARMENIAN_FONTS (todo)
# BENGALI_FONTS (todo)
# BURMESE_FONTS (todo)
# CHI_SIM_FONTS (todo)
# CHI_TRA_FONTS (todo)

# DEVANAGARI_FONTS (see also external links below)
apt-get install fonts-deva

# EARLY_LATIN_FONTS (todo)
# FRAKTUR_FONTS (todo)
# GEORGIAN_FONTS (todo)
# GREEK_FONTS (todo)
# GUJARATI_FONTS (todo)
# HEBREW_FONTS (todo)

# JPN_FONTS (todo)
apt-get install fonts-noto-cjk fonts-japanese-mincho.ttf fonts-takao-gothic fonts-vlgothic

# KANNADA_FONTS (todo)
# KHMER_FONTS (todo)
# KOREAN_FONTS (todo)
# KURDISH_FONTS (todo)
# KYRGYZ_FONTS (todo)
# LAOTHIAN_FONTS (todo)

# LATIN_FONTS
apt-get install fonts-dejavu gsfonts ttf-mscorefonts-installer

# MALAYALAM_FONTS (todo)

# NEOLATIN_FONTS (still incomplete)
apt-get install fonts-ebgaramond fonts-gfs-didot fonts-gfs-didot-classic fonts-junicode

# NORTH_AMERICAN_ABORIGINAL_FONTS (todo)
# OLD_GEORGIAN_FONTS (todo)
# ORIYA_FONTS (todo)
# PERSIAN_FONTS (todo)
# PUNJABI_FONTS (todo)
# RUSSIAN_FONTS (todo)
# SINHALA_FONTS (todo)
# SYRIAC_FONTS (todo)
# TAMIL_FONTS (todo)
# TELUGU_FONTS (todo)
# THAANA_FONTS (todo)
# THAI_FONTS (todo)
# TIBETAN_FONTS (todo)
# VERTICAL_FONTS (todo)
# VIETNAMESE_FONTS (todo)

已安裝的字型會由命令 fc-list 顯示。另請參閱 Debian wiki

text2image --fonts_dir /usr/share/fonts --list_available_fonts 也會顯示所有字型。

(大多是免費)字型的來源

涵蓋許多文字的字型

拉丁字型

阿拉伯字型

天城文字型

Fraktur 字型

希伯來字型

字型集合

更多關於字型的資訊