I'm using tesseract.js to do OCR, but when I change exampleImage, I get this error. I can't find any information at all about this error. Thank you in advance.
app.js
const exampleImage = 'https://d1q6f0aelx0por.cloudfront.net/product-logos/5431a80b-9ab9-486c-906a-e3d4b5ccaa96-hello-world.png';
const Tesseract=require('tesseract.js');
const worker = Tesseract.createWorker({
logger: m => console.log(m)
});
Tesseract.setLogging(true);
work();
async function work() {
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
let result = await worker.detect(exampleImage);
console.log(result.data);
result = await worker.recognize(exampleImage);
console.log(result.data);
await worker.terminate();
}
Console.log
Error: Failed to detect OS
at ChildProcess.<anonymous> (c:\Users\jorda\AppData\Local\Programs\Microsoft VS Code\bin\Example\node_modules\tesseract.js\src\createWorker.js:173:15)
at ChildProcess.emit (events.js:311:20)
at emit (internal/child_process.js:876:12)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
Your usage and their documentations use cases not matching did you check their documentation?
Try to write like them for example;
const { createWorker } = require('tesseract.js');
const exampleImage = 'https://d1q6f0aelx0por.cloudfront.net/product-logos/5431a80b-9ab9-486c-906a-e3d4b5ccaa96-hello-world.png';
const worker = createWorker({
logger: m => console.log(m), // Add logger here
});
(async () => {
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize(exampleImage);
console.log(text);
await worker.terminate();
})();
Nevermind, I was using too small of an image. With a larger image, the code worked fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.