-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesseract.js
23 lines (22 loc) · 840 Bytes
/
tesseract.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const { createWorker } = require('tesseract.js');
const connectDB = require('./db.js');
const path = require('path');
const app = require('express').Router();
const models = require('../models/models.js');
const labelExtractor = require('./labelExtractor.js');
module.exports = function (imagePath) {
return (async () => {
const worker = createWorker({
logger: () => null,
langPath: path.resolve('./mlData'),
});
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize(imagePath);
await worker.terminate();
capsText = text.toUpperCase(); //Convert text to uppercase for uniformity
console.log(capsText);
return labelExtractor(capsText);
})();
};