github:https://github.com/naptha/tesseract.js
可实现多语言识别,中英文混合识别demo如下:
<script setup lang="ts">
import Tesseract from "tesseract.js"
// 方式1:
Tesseract.recognize(
'http://localhost:5173/vue.jpg',
'eng+chi_sim',
).then((d) => {
console.log(d.data.text);
}).catch(error =>{
console.log(error);
});
// 方式2:
(async () => {
const worker = await Tesseract.createWorker('eng+chi_sim');
const ret = await worker.recognize('http://localhost:5173/vue.jpg');
console.log(ret.data.text);
await worker.terminate();
})();
</script>