Created
October 7, 2019 00:39
-
-
Save jeromewu/44bdc2c686899775596e981b416a196e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src='https://unpkg.com/tesseract.js@v2.0.0-beta.1/dist/tesseract.min.js'></script> | |
</head> | |
<body> | |
<button id="recBtn">Recognize</button> | |
<script> | |
const recognize = async () => { | |
const { createWorker } = Tesseract; | |
const worker = createWorker({ | |
logger: m => console.log(m), | |
}); | |
const image = new Image(); | |
image.src = 'https://tesseract.projectnaptha.com/img/eng_bw.png'; | |
await worker.load(); | |
await worker.loadLanguage('eng'); | |
await worker.initialize('eng'); | |
const { data: { text } } = await worker.recognize(image.src); | |
console.log(text); | |
}; | |
document.getElementById('recBtn').addEventListener('click', recognize); | |
</script> | |
</body> | |
</html> |
The code above only works in tesseract.js 2.0.0-beta.1, please make sure you are using the right version.
Hey thanks for the update! I changed my version to yours and it works perfectly so thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sorry when I try this I get an error saying that createWorker isn't defined. Since I am including Tesseract from a cdn I am using a script tag in my main html page and i am setting Tesseract = window.Tesseract......Perhaps this has something to do with why create worker is undefined?