Tesseract OCR

#1

I have an issue, I’m using ionic 4 and the recognize method on my Tesseract OCR is throwing an error to do with the .let .complete on the ngorocessor … my code is as follow and appreciate any help

import { Component } from ‘@angular/core’;
import { NavController, ActionSheetController, LoadingController } from ‘@ionic/angular’;
import { Camera, PictureSourceType } from ‘@ionic-native/camera/ngx’;
import * as Tesseract from ‘tesseract.js’
import { NgProgress } from ‘@ngx-progressbar/core’;

@Component({
selector: ‘app-home’,
templateUrl: ‘home.page.html’,
styleUrls: [‘home.page.scss’],
})
export class HomePage {

selectedImage: string;
imageText: string;

constructor(public navCtrl: NavController, private camera: Camera, private actionSheetCtrl: ActionSheetController, public progress: NgProgress) {
}

async selectSource() {
  let actionSheet = await this.actionSheetCtrl.create({
    buttons: [
      {
        text: 'Use Library',
        handler: () => {
          this.getPicture(this.camera.PictureSourceType.PHOTOLIBRARY);
        }
      }, {
        text: 'Capture Image',
        handler: () => {
          this.getPicture(this.camera.PictureSourceType.CAMERA);
        }
      }, {
        text: 'Cancel',
        role: 'cancel'
      }
    ]
  });
  await actionSheet.present();
}

getPicture(sourceType: PictureSourceType) {
  this.camera.getPicture({
    quality: 100,
    destinationType: this.camera.DestinationType.DATA_URL,
    sourceType: sourceType,
    allowEdit: true,
    saveToPhotoAlbum: false,
    correctOrientation: true
  }).then((imageData) => {
    this.selectedImage = `data:image/jpeg;base64,${imageData}`;
  });
}

recognizeImage() {
  /*Tesseract.recognize(this.selectedImage)
  .progress(message => {
    console.log(message);
    if (message.status === 'recognizing text')
    this.progress.Set(message.progress);
  })
  .catch(err => console.error(err))
  .then(result => {
    this.imageText = result.text;
  })
  .finally(resultOrError => {
    alert(resultOrError);
    this.progress.Complete();
  });*/
}

}

1 Like