'Extract Data from Image to Text in angular
I want to extract the data from image using Tesseract.js in my angular project.
Can anybody given an example for how to do the extraction of data from image
Solution 1:[1]
Check project github repository for documentation and examples
import { TesseractWorker } from 'tesseract.js';
const worker = new TesseractWorker();
worker.recognize(myImage)
.progress(progress => {
console.log('progress', progress);
}).then(result => {
console.log('result', result);
});
Solution 2:[2]
You can try out below logic, which was implemented part of poc:-
import { Component } from '@angular/core';
import { createWorker } from 'tesseract.js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'poc for ocr';
ocrResult = 'Loading the library...';
constructor() {
this.doOCR();
}
async doOCR() {
const worker = createWorker({
logger: m => console.log(m),
});
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize('<your image>');
this.ocrResult = text;
console.log(text);
await worker.terminate();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xesenix |
| Solution 2 | Kishore Konangi |
