Skip to content

OCR

传入图片和对应的语言类型,返回图片中的文本。

API

Return

参数说明类型
success是否解析成功boolean
data解析成功后的对象obj
message解析成功或失败的原因string

Options

参数说明类型默认值
images图片的数组,支持urlbase64Array<string>
language指定生成文本的语言,具体参数见lang-codestring
langPath使用的时候需要能访问cdn.jsdelivr.net,会下载对应的语言包,如果无法访问,也可以将语言包放在本地,传入对应的 目录 路径string可选参数,默认走网络下载

Example

js
import { ocr } from 'ranuts';

const images = ['https://chaxus.github.io/ran/ocr/eng.png'];
const languages = 'eng';
ocr({ images, language }).then((res) => {
  console.log(res.data?.[0].data.text);
});
// Mild Splendour of the various-vested Night!
// Mother of wildly-working visions! hail
// I watch thy gliding, while with watery light
// Thy weak eye glimmers through a fleecy veil;
// And when thou lovest thy pale orb to shroud
// Behind the gather’d blackness lost on high;
// And when thou dartest from the wind-rent cloud
// Thy placid lightning o’er the awaken’d sky.

Lang Code

Lang CodeLanguage
afrAfrikaans
amhAmharic
araArabic
asmAssamese
azeAzerbaijani
aze_cyrlAzerbaijani - Cyrillic
belBelarusian
benBengali
bodTibetan
bosBosnian
bulBulgarian
catCatalan; Valencian
cebCebuano
cesCzech
chi_simChinese - Simplified
chi_traChinese - Traditional
chrCherokee
cymWelsh
danDanish
deuGerman
dzoDzongkha
ellGreek, Modern (1453-)
engEnglish
enmEnglish, Middle (1100-1500)
epoEsperanto
estEstonian
eusBasque
fasPersian
finFinnish
fraFrench
frkGerman Fraktur
frmFrench, Middle (ca. 1400-1600)
gleIrish
glgGalician
grcGreek, Ancient (-1453)
gujGujarati
hatHaitian; Haitian Creole
hebHebrew
hinHindi
hrvCroatian
hunHungarian
ikuInuktitut
indIndonesian
islIcelandic
itaItalian
ita_oldItalian - Old
javJavanese
jpnJapanese
kanKannada
katGeorgian
kat_oldGeorgian - Old
kazKazakh
khmCentral Khmer
kirKirghiz; Kyrgyz
korKorean
kurKurdish
laoLao
latLatin
lavLatvian
litLithuanian
malMalayalam
marMarathi
mkdMacedonian
mltMaltese
msaMalay
myaBurmese
nepNepali
nldDutch; Flemish
norNorwegian
oriOriya
panPanjabi; Punjabi
polPolish
porPortuguese
pusPushto; Pashto
ronRomanian; Moldavian; Moldovan
rusRussian
sanSanskrit
sinSinhala; Sinhalese
slkSlovak
slvSlovenian
spaSpanish; Castilian
spa_oldSpanish; Castilian - Old
sqiAlbanian
srpSerbian
srp_latnSerbian - Latin
swaSwahili
sweSwedish
syrSyriac
tamTamil
telTelugu
tgkTajik
tglTagalog
thaThai
tirTigrinya
turTurkish
uigUighur; Uyghur
ukrUkrainian
urdUrdu
uzbUzbek
uzb_cyrlUzbek - Cyrillic
vieVietnamese
yidYiddish

Released under the MIT License.