EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

How to recognize text from a mask or vertices with live camera, MLKIT, TextRecognition? #1792

Closed calleja23 closed 3 years ago

calleja23 commented 3 years ago

Hi, I am trying to read a text with ipad`s camera. But the result text does not appear in the image. The text you read is a few centimeters or inches higher. The problem only is in IOS:

.ts

import { Component, ViewChild,NgZone, OnDestroy, OnInit, ElementRef } from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import { getString, setString, remove, } from "tns-core-modules/application-settings"; const firebase = require("nativescript-plugin-firebase"); import { Location } from "@angular/common"; import { RouterExtensions } from "nativescript-angular/router"; import {isAndroid, isIOS} from "tns-core-modules/platform"; import {ImageSource} from "tns-core-modules/image-source"; import { MLKitRecognizeTextResultBlock,MLKitRecognizeTextResult,MLKitRecognizeTextResultLine,MLKitTextRecognition,recognizeTextOnDevice } from "nativescript-plugin-firebase/mlkit/textrecognition";

  import {
MLKitCameraView,MLKitVisionOptions
} from "nativescript-plugin-firebase/mlkit"
@Component({
  selector: 'ns-capture',
  moduleId: module.id,
  styleUrls: ['./capture.component.css'],
  templateUrl: './capture.component.html'
})
export class CaptureComponent implements OnInit, OnDestroy {
  public imageSource: ImageSource;
  public matricula;
  public imagene;
  public pause=false;
  public torchOn=false;
  public context;
  public isios= false;
  public isandroid=false;
  @ViewChild('myElement', {static:false }) myElement: ElementRef;
 camera: MLKitCameraView
 options:MLKitVisionOptions
  blocks: Array<MLKitRecognizeTextResultBlock>;
  pickedImage:ImageSource
  prueba: MLKitRecognizeTextResultLine
  constructor(private zone: NgZone, public location:Location,private route: ActivatedRoute,private routerExtensions: RouterExtensions) {
    (isIOS==true?this.isios=true:this.isios=false);
    (isAndroid==true?this.isandroid=true:this.isandroid=false);
    this.camera
}

  ngOnInit(): void {
    firebase.init({
        showNotificationsWhenInForeground: true,
        showNotifications: true,
        onPushTokenReceivedCallback: (token) => {
        },
        onMessageReceivedCallback: (message) => {
          const self=this;
          let contentUrl:string=null;
          let contentType:string=null;
          let route:string="";
          if (message.foreground){

          }else{
            try{
            }catch(e){
                console.log("message background",e)

            }

          }
        },

      })
        .then(() => {
          console.log('[Firebase] Initialized');
          console.log("  this.myElement",  this.myElement)

        })
        .catch(error => {
          console.log('[Firebase] Initialize', { error });
        });

  }
  ngOnDestroy() {}
  setPlateNumber(){
  }
  onTextRecognitionResult(scanResult: any): void {
    const value: MLKitRecognizeTextResult = scanResult.value;
    this.blocks = value.blocks;
      if (isIOS){
        if(scanResult.value.blocks[0] &&  scanResult.value.blocks[0]['lines'] ){
            this.matricula=scanResult.value.blocks[0]['lines'][0]['text']

        }
      }else{
        this.matricula=scanResult.value.blocks[0]['lines'][0]['text']
        const value: MLKitRecognizeTextResult = scanResult.value;
        console.log("[[[[[[scanResult1]]]]]]1",scanResult.value.blocks)
      }
}

  goToHome(event){
    this.zone.run(()=>{
        this.pause= true;
        var matricula=  getString("MATRICULA")
        if(matricula && matricula!== undefined){
            remove("MATRICULA")
        }
        setString("MATRICULA",this.matricula);
        this.location.back()
    })
}
goBack(){
    this.zone.run(()=>{
        this.pause= true;
        var matricula=  getString("MATRICULA")
        if(matricula && matricula!== undefined){
            remove("MATRICULA")
        }
        this.location.back()
    })
}
}

image

Could you help me read the first line, or read what's in the frames? Thanks

calleja23 commented 3 years ago

Hi, i changed in mlkit-cameraview.ios.js line 49 the resolution fro AVCaptureSessionPreset1280x720 to AVCaptureSessionPreset640x480

image

Can you help me read only what is within the limits?? thanks :)