离子-Tesseract和解析MRZ

时间:2018-08-14 11:50:24

标签: javascript ionic-framework ocr tesseract

我正试图将Tesseract的OCR的值放入MRZ解析器中,但无济于事。如果我手动传递一个字符串,它会按预期工作,并显示MRZ解析的详细信息。

进口:

import Tesseract from 'tesseract.js'
import * as mrzParser from 'newtondev-mrz-parser';

功能:

Tesseract.create({
    langPath: "https://github.com/Exteris/tesseract-mrz/blob/master/lang/OCRB.traineddata.gz?raw=true"
  }).recognize(document.getElementById('image'), "ocrb")
    .progress((progress) => {
        console.log('progress', JSON.stringify(progress));
    })
    .catch(err => console.error(err))
    .then(tesseractResult => {

       //the alert works and shows the actual text from an image
       alert(tesseractResult.text); 

       //manually passing the string works
       var xdata  = 'P<CANMARTIN<<SARAH<<<<<<<<<<<<<<<<<<<<<<<<<<ZE000509<9CAN8501019F2301147<<<<<<<<<<<<<<08';

       //this does *not* work
       //var xdata  = tesseractResult.text;

       this.imageText = mrzParser.parse(xdata);
       alert(JSON.stringify(this.imageText));

    })

    .finally(resultOrError => console.log(resultOrError));

不幸的是,错误日志中没有任何内容。

0 个答案:

没有答案