Skip to content

Instantly share code, notes, and snippets.

@jeromewu
Created October 7, 2019 00:39
Show Gist options
  • Save jeromewu/44bdc2c686899775596e981b416a196e to your computer and use it in GitHub Desktop.
Save jeromewu/44bdc2c686899775596e981b416a196e to your computer and use it in GitHub Desktop.
<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>
@lwardlegit
Copy link

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?

@jeromewu
Copy link
Author

jeromewu commented Oct 8, 2019

The code above only works in tesseract.js 2.0.0-beta.1, please make sure you are using the right version.

@lwardlegit
Copy link

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