Skip to content

Commit

Permalink
feat(firebase-vision): add image labelling (#3569)
Browse files Browse the repository at this point in the history
* feat(firebase-vision): add image labelling

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

* fix(firebase-vision): fix interfaces
  • Loading branch information
alon22 committed Nov 19, 2020
1 parent fd0cddc commit af114f4
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions 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,
Expand Down Expand Up @@ -96,6 +130,8 @@ export interface Barcode {
rawValue: string
displayValue: string
cornerPoints: any
imageHeight: number
imageWidth: number
email: BarcodeEmail
phone: BarcodePhone
sms: BarcodeSms
Expand Down Expand Up @@ -180,6 +216,11 @@ export interface BarcodeDriverLicense {
issuingCountry: string
}

export interface ImageLabel {
index: number,
confidence: number,
text: string
}
/**
* @name Firebase Vision
* @description
Expand All @@ -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({
Expand All @@ -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;
}
}

0 comments on commit af114f4

Please sign in to comment.