【问题标题】:Extract Data from Image to Text in angular以角度将数据从图像提取到文本
【发布时间】:2019-07-01 12:49:23
【问题描述】:

我想在我的 Angular 项目中使用 Tesseract.js 从图像中提取数据。

谁能举例说明如何从图像中提取数据

【问题讨论】:

    标签: angular tesseract tesseract.js


    【解决方案1】:

    检查项目 github 存储库中的 documentationexamples

    import { TesseractWorker } from 'tesseract.js';
    const worker = new TesseractWorker();
    
    worker.recognize(myImage)
      .progress(progress => {
        console.log('progress', progress);
      }).then(result => {
        console.log('result', result);
      });
    

    【讨论】:

    • 或者你有问题如何在角度使用该代码?然后也许检查angular + webworkers
    • 同时添加 import { TesseractWorker } from 'tesseract.js';模块 '"../../../node_modules/@types/tesseract.js"' has no export member 'TesseractWorker' 错误即将到来。你能帮我解决这个问题吗? @Xesenix
    • 从我在快速查找中看到的应该可以工作我需要创建自己的示例来检查几个小时后回家后会出现什么问题
    【解决方案2】:

    你可以试试下面的逻辑,它是 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();
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 2014-07-31
      相关资源
      最近更新 更多