feat(firebase-vision): add image labelling (#3569)

* feat(firebase-vision): add image labelling

* style(firebase-vision): update asterisks to pass lint

* fix(firebase-vision): fix interfaces
This commit is contained in:
Rubén Alonso Silvestre 2020-11-19 08:35:04 +01:00 committed by GitHub
parent fd0cddc9d0
commit af114f48e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,40 @@
import { Injectable } from '@angular/core';
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
export interface Text {
text: string;
blocks: TextLine[];
imageHeight: number;
imageWidth: number;
}
export interface TextLine extends TextBlock {
lines: TextElement[]
}
export interface TextElement extends TextBlock {
elements: TextBlock[]
}
export interface TextBlock {
text: string;
cornerPoints: TextPoint[]
frame: TextFrame
recognizedLanguages: string
}
export interface TextPoint {
x: number,
y: number
}
export interface TextFrame {
x: number,
y: number,
width: number,
height: number
}
export enum BarcodeFormat {
UNKNOWN = -1,
ALL_FORMATS = 0,
@ -96,6 +130,8 @@ export interface Barcode {
rawValue: string
displayValue: string
cornerPoints: any
imageHeight: number
imageWidth: number
email: BarcodeEmail
phone: BarcodePhone
sms: BarcodeSms
@ -180,6 +216,11 @@ export interface BarcodeDriverLicense {
issuingCountry: string
}
export interface ImageLabel {
index: number,
confidence: number,
text: string
}
/**
* @name Firebase Vision
* @description
@ -203,6 +244,10 @@ export interface BarcodeDriverLicense {
* .then((res: Barcode[]) => console.log(res))
* .catch((error: string) => console.error(error));
*
* this.firebaseVision.imageLabeler(FILE_URI)
* .then((res: ImageLabel[]) => console.log(res))
* .catch((error: string) => console.error(error));
*
* ```
*/
@Plugin({
@ -220,12 +265,25 @@ export class FirebaseVision extends IonicNativePlugin {
* @return {Promise<string>} Returns a promise that fulfills with the text in the image
*/
@Cordova()
onDeviceTextRecognizer(file_uri: string): Promise<string> {
onDeviceTextRecognizer(file_uri: string): Promise<Text> {
return;
}
/**
* Read data from Barcode
* @param file_uri {string} Image URI
* @return {Promise<Barcode[]>} Returns a promise that fulfills with the data in barcode
*/
@Cordova()
barcodeDetector(file_uri: string): Promise<Barcode[]> {
return;
}
/**
* Recognize object in image
* @param file_uri {string} Image URI
* @return {Promise<ImageLabel[]>} Returns a promise that fulfills with the information about entities in an image
*/
@Cordova()
imageLabeler(file_uri: string): Promise<ImageLabel[]> {
return;
}
}