1- import { Component , NgZone } from "@angular/core" ;
1+ import { Component } from "@angular/core" ;
22import { ImageSource } from "tns-core-modules/image-source" ;
33
44import { BarcodeFormat , MLKitScanBarcodesResult } from "nativescript-plugin-firebase/mlkit/barcodescanning" ;
55import { MLKitRecognizeTextResult } from "nativescript-plugin-firebase/mlkit/textrecognition" ;
6+ import { MLKitLandmarkRecognitionResult } from "nativescript-plugin-firebase/mlkit/landmarkrecognition" ;
67import { MLKitDetectFacesResult } from "nativescript-plugin-firebase/mlkit/facedetection" ;
7- import { Image } from "tns-core-modules/ui/image" ;
88import { action } from "tns-core-modules/ui/dialogs" ;
99import { ImageAsset } from "tns-core-modules/image-asset" ;
1010import * as ImagePicker from "nativescript-imagepicker" ;
1111import * as Camera from "nativescript-camera" ;
1212import { RouterExtensions } from "nativescript-angular" ;
13+ import { isIOS } from "tns-core-modules/platform" ;
14+ import { MLKitImageLabelingResult } from "nativescript-plugin-firebase/mlkit/imagelabeling" ;
1315
1416const firebase = require ( "nativescript-plugin-firebase" ) ;
1517
@@ -19,18 +21,16 @@ const firebase = require("nativescript-plugin-firebase");
1921 templateUrl : "./mlkit.component.html" ,
2022} )
2123export class MLKitComponent {
22- public scannedImage : Image ;
2324
2425 private mlkitFeatures : Array < string > = [
2526 "Text recognition" ,
2627 "Barcode scanning" ,
2728 "Face detection" ,
2829 "Image labeling" ,
29- "Landmark recognition"
30+ "Landmark recognition (cloud) "
3031 ] ;
3132
32- constructor ( private zone : NgZone ,
33- private routerExtensions : RouterExtensions ) {
33+ constructor ( private routerExtensions : RouterExtensions ) {
3434 }
3535
3636 fromCameraFeed ( ) : void {
@@ -48,6 +48,13 @@ export class MLKitComponent {
4848 to = "/tabs/mlkit/facedetection" ;
4949 } else if ( pickedItem === "Image labeling" ) {
5050 to = "/tabs/mlkit/imagelabeling" ;
51+ } else if ( pickedItem === "Landmark recognition (cloud)" ) {
52+ alert ( {
53+ title : `Not available` ,
54+ message : `Landmark recognition is currently cloud-only, so that would be a bit too taxing on your dataplan.` ,
55+ okButtonText : "Gotcha!"
56+ } ) ;
57+ return ;
5158 }
5259 if ( to !== undefined ) {
5360 this . routerExtensions . navigate ( [ to ] ,
@@ -64,9 +71,12 @@ export class MLKitComponent {
6471 }
6572
6673 fromCameraPicture ( ) : void {
74+ if ( ! isIOS ) {
75+ Camera . requestPermissions ( ) ;
76+ }
6777 Camera . takePicture ( {
68- width : 1000 ,
69- height : 1000 ,
78+ width : 800 ,
79+ height : 800 ,
7080 keepAspectRatio : true ,
7181 saveToGallery : false ,
7282 cameraFacing : "rear"
@@ -91,8 +101,8 @@ export class MLKitComponent {
91101
92102 const selected = selection [ 0 ] ;
93103 console . log ( ">>> selected: " + selected ) ;
94- selected . options . height = 1000 ;
95- selected . options . width = 1000 ;
104+ selected . options . height = 800 ;
105+ selected . options . width = 800 ;
96106 selected . options . keepAspectRatio = true ;
97107 selected . getImageAsync ( ( image : any , error : any ) => {
98108 console . log ( ">>> error: " + error ) ;
@@ -126,6 +136,8 @@ export class MLKitComponent {
126136 this . detectFaces ( imageSource ) ;
127137 } else if ( pickedItem === "Image labeling" ) {
128138 this . labelImage ( imageSource ) ;
139+ } else if ( pickedItem === "Landmark recognition (cloud)" ) {
140+ this . recognizeLandmark ( imageSource ) ;
129141 }
130142 } ) ;
131143 }
@@ -144,6 +156,20 @@ export class MLKitComponent {
144156 . catch ( errorMessage => console . log ( "ML Kit error: " + errorMessage ) ) ;
145157 }
146158
159+ private recognizeLandmark ( imageSource : ImageSource ) : void {
160+ firebase . mlkit . landmarkrecognition . recognizeLandmark ( {
161+ image : imageSource
162+ } ) . then (
163+ ( result : MLKitLandmarkRecognitionResult ) => {
164+ alert ( {
165+ title : `Result` ,
166+ message : JSON . stringify ( result . landmarks ) ,
167+ okButtonText : "OK"
168+ } ) ;
169+ } )
170+ . catch ( errorMessage => console . log ( "ML Kit error: " + errorMessage ) ) ;
171+ }
172+
147173 private scanBarcode ( imageSource : ImageSource ) : void {
148174 firebase . mlkit . barcodescanning . scanBarcodes ( {
149175 image : imageSource ,
@@ -178,10 +204,10 @@ export class MLKitComponent {
178204 image : imageSource ,
179205 confidenceThreshold : 0.3
180206 } ) . then (
181- ( result : MLKitDetectFacesResult ) => {
207+ ( result : MLKitImageLabelingResult ) => {
182208 alert ( {
183209 title : `Result` ,
184- message : JSON . stringify ( result . faces ) ,
210+ message : JSON . stringify ( result . labels ) ,
185211 okButtonText : "OK"
186212 } ) ;
187213 } )
0 commit comments