tesseract-ocrHow can I use Tesseract OCR with Node.js?
Using Tesseract OCR with Node.js is possible thanks to the Tesseract.js library. Tesseract.js is a JavaScript library that wraps the Tesseract OCR engine. It allows you to use the Tesseract OCR engine in Node.js applications. Here's an example of how to use Tesseract.js in Node.js:
const { TesseractWorker } = require("tesseract.js");
const worker = new TesseractWorker();
worker
.recognize("example.png")
.progress(message => {
console.log(message);
})
.then(result => {
console.log(result.text);
})
.finally(() => worker.terminate());
This code will recognize the text in the example.png image and output it in the console.
The code consists of the following parts:
-
const { TesseractWorker } = require("tesseract.js");
- this line imports the TesseractWorker class from the tesseract.js library. -
const worker = new TesseractWorker();
- this line creates a new instance of the TesseractWorker class. -
worker.recognize("example.png")
- this line calls the recognize() method of the worker instance, passing in the path to the image that should be recognized. -
.progress(message => { console.log(message); })
- this line adds a progress handler to the worker instance. This handler will be called each time the OCR engine makes progress and will output the progress message to the console. -
.then(result => { console.log(result.text); })
- this line adds a then handler to the worker instance. This handler will be called when the OCR engine is done and will output the recognized text to the console. -
.finally(() => worker.terminate());
- this line adds a finally handler to the worker instance. This handler will be called when the OCR engine is done and will terminate the worker instance.
For more information about Tesseract.js and how to use it in Node.js applications, please refer to the following links:
More of Tesseract Ocr
- How do I download the Tesseract OCR software from the University of Mannheim?
- How do I set the Windows path for Tesseract OCR?
- How do I add Tesseract OCR to my environment variables?
- How can I use UiPath and Tesseract OCR together to automate a process?
- How can I tune Tesseract OCR for optimal accuracy?
- How can I use tesseract ocr portable to recognize text in images?
- How can I use Tesseract OCR with Node.js?
- How can I use Tesseract OCR to set the Page Segmentation Mode (PSM) for an image?
- How to use Tesseract OCR to recognize numbers?
- How can I compare Tesseract OCR and OpenCV for optical character recognition?
See more codes...