From af114f48e46b4f7f1ce66bb2906585158aa5cff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Alonso=20Silvestre?= Date: Thu, 19 Nov 2020 08:35:04 +0100 Subject: [PATCH] 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 --- .../plugins/firebase-vision/index.ts | 62 ++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/@ionic-native/plugins/firebase-vision/index.ts b/src/@ionic-native/plugins/firebase-vision/index.ts index cb2749d2e9..94bacbd425 100644 --- a/src/@ionic-native/plugins/firebase-vision/index.ts +++ b/src/@ionic-native/plugins/firebase-vision/index.ts @@ -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} Returns a promise that fulfills with the text in the image */ @Cordova() - onDeviceTextRecognizer(file_uri: string): Promise { + onDeviceTextRecognizer(file_uri: string): Promise { return; } - + /** + * Read data from Barcode + * @param file_uri {string} Image URI + * @return {Promise} Returns a promise that fulfills with the data in barcode + */ @Cordova() barcodeDetector(file_uri: string): Promise { return; } + /** + * Recognize object in image + * @param file_uri {string} Image URI + * @return {Promise} Returns a promise that fulfills with the information about entities in an image + */ + @Cordova() + imageLabeler(file_uri: string): Promise { + return; + } }