Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

javascript - how to use Tesseract.recognize in nodejs

I want to make an OCR program but I fund some problems during the declaration of 'Tesseract.recognize' method

here is my code :

const express = require('express');

const fs= require('fs');

const multer = require('multer');

const Tesseract = require('Tesseract.js');

const app = express();

// app.use(bodyParser.urlencoded({extended: true}))

const PORT = process.env.PORT | 5000;   

var Storage = multer.diskStorage({
    destination: function (req, file, callback) {
      callback(null, 'images')
    },
    filename: function (req, file, callback) {
      callback(null, file.orignalname);
    }
});
var upload = multer({
 storage: Storage 
}).array('image', 3);
//route
app.post('/', (req, res) => {});

app.post('/upload', (req, res) => {
    console.log(req.file);
    upload(req, res , err => {
        if (err) {
            console.log(err);
            return res.send('somthing went wrong');
        }
        return res.send('file uploaded successfully');
    });
});

var image = fs.readFileSync(__dirname + '/images/cv.jpg', 
    {
        encoding:null
    });

Tesseract.recognize(image)
    .progress(function(p) {
        console.log('progress', p);
    })
    .then(function(result) {
        res.send('result', result);
    });

app.listen(PORT, () => {
    console.log('Server running on PORT ${PORT}')
});

and this is my terminal result:

.progress(function(p) {
     ^

TypeError: Tesseract.recognize(...).progress is not a function
    at Object.<anonymous> (C:UsersdeDesktopMR.Azmani ProjectANGULARocrserver.js:46:6)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
[nodemon] app crashed - waiting for file changes before starting...

and this it what is the result how should look like in the treminal during the process enter image description here

and this is the final result in the termilal

enter image description here

thank you

question from:https://stackoverflow.com/questions/65835056/how-to-use-tesseract-recognize-in-nodejs

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.progress was removed in version 2 of tesseract.js (there's a blog post about that here. Version one is still on Github here, and probably still works, so you can npm i [email protected] to get the behavior you're expecting, or see the docs and examples for the current version to get your code updated for v2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...