Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
const fs = require("fs");
const multer = require('multer');
const { createWorker } = require("tesseract.js");
const worker = createWorker();
//Storage
const storage = multer.diskStorage({
destination: (req,file,cb) => {
cb(null, "./uploads");
filename: (req,file,cb) => {
cb(null, file.originalname);
const upload = multer({storage: storage}).single("avatar");
app.set('view engine', 'ejs');
//route
app.get('/',(req,res)=>{
res.render('index');
app.post('/upload',(req,res) => {
upload(req,res, err => {
fs.readFile(`./uploads/${req.file.originalname}`,(err,data) => {
if(err) return console.log('This is your error',err);
worker
.recognize(data, "eng", {tessjs_create_pdf: '1'})
.progress(progress => {
console.log(progress);
.then(result => {
res.send(result.text);
.finally(() => worker.terminate())
//Start Up our server
const PORT = 5000 || process.env.PORT;
app.listen(PORT, () => console.log(`Hey I am running on port ${PORT}`));
the error I get is this
D:\ML\OCR\app.js:34
.progress(progress => {
TypeError: worker.recognize(...).progress is not a function
at D:\ML\OCR\app.js:34:18
I know worker.recognize/.progress is decapitated but can someone please correct this code.
Thank you.
I am trying to create an OCR using tesseract.js . watching this video: https://www.youtube.com/watch?v=a1I3tcALTlc
But I am not able to find a solution.
I think the issue is that the code is out of date.
Try this
async function getTextFromImage() {
await worker.load()
await worker.loadLanguage('eng')
await worker.initialize('eng')
const { data: { text } } = await worker.recognize(data);
res.send(text);
console.log(text);
await worker.terminate()
getTextFromImage();
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.