11import { ImageSource } from "tns-core-modules/image-source" ;
22import { MLKitOptions } from "../" ;
3- import { MLKitLandmarkRecognitionOptions , MLKitLandmarkRecognitionResult } from "./" ;
4- import { MLKitLandmarkRecognition as MLKitLandmarkRecognitionBase } from "./landmarkrecognition-common " ;
3+ import { MLKitLandmarkRecognitionCloudOptions , MLKitLandmarkRecognitionCloudResult } from "./" ;
4+ import { MLKitCloudModelType } from "../index " ;
55
6- export class MLKitLandmarkRecognition extends MLKitLandmarkRecognitionBase {
7-
8- protected createDetector ( ) : any {
9- return getDetector ( this . maxResults ) ;
10- }
11-
12- protected createSuccessListener ( ) : any {
13- return ( landmarks : NSArray < FIRVisionCloudLandmark > , error : NSError ) => {
14- if ( error !== null ) {
15- console . log ( error . localizedDescription ) ;
16-
17- } else if ( landmarks !== null && landmarks . count > 0 ) {
18- const result = < MLKitLandmarkRecognitionResult > {
19- landmarks : [ ]
20- } ;
21-
22- for ( let i = 0 , l = landmarks . count ; i < l ; i ++ ) {
23- const landmark : FIRVisionCloudLandmark = landmarks . objectAtIndex ( i ) ;
24- console . log ( ">> detected landmark: " + landmark ) ;
25- result . landmarks . push ( {
26- name : landmark . landmark ,
27- confidence : landmark . confidence
28- } ) ;
29- }
30-
31- console . log ( ">>> notify " + MLKitLandmarkRecognition . scanResultEvent + " with " + JSON . stringify ( result ) ) ;
32- this . notify ( {
33- eventName : MLKitLandmarkRecognition . scanResultEvent ,
34- object : this ,
35- value : result
36- } ) ;
37- }
38- }
39- }
40-
41- protected rotateRecording ( ) : boolean {
42- return false ;
43- }
44- }
45-
46- function getDetector ( maxResults : number ) : FIRVisionCloudLandmarkDetector {
6+ function getDetector ( modelType : MLKitCloudModelType , maxResults : number ) : FIRVisionCloudLandmarkDetector {
477 const firVision : FIRVision = FIRVision . vision ( ) ;
488 const fIRVisionCloudDetectorOptions = FIRVisionCloudDetectorOptions . alloc ( ) ;
49- fIRVisionCloudDetectorOptions . maxResults = maxResults ;
9+ fIRVisionCloudDetectorOptions . modelType = modelType === "latest" ? FIRVisionCloudModelType . Latest : FIRVisionCloudModelType . Stable ;
10+ fIRVisionCloudDetectorOptions . maxResults = maxResults || 10 ;
5011 return firVision . cloudLandmarkDetectorWithOptions ( fIRVisionCloudDetectorOptions ) ;
5112}
5213
53- export function recognizeLandmark ( options : MLKitLandmarkRecognitionOptions ) : Promise < MLKitLandmarkRecognitionResult > {
14+ export function recognizeLandmarksCloud ( options : MLKitLandmarkRecognitionCloudOptions ) : Promise < MLKitLandmarkRecognitionCloudResult > {
5415 return new Promise ( ( resolve , reject ) => {
5516 try {
56- const landmarkDetector = getDetector ( options . maxResults || 10 ) ;
17+ const landmarkDetector = getDetector ( options . modelType , options . maxResults ) ;
5718
5819 landmarkDetector . detectInImageCompletion ( getImage ( options ) , ( landmarks : NSArray < FIRVisionCloudLandmark > , error : NSError ) => {
5920 if ( error !== null ) {
6021 reject ( error . localizedDescription ) ;
6122
6223 } else if ( landmarks !== null ) {
63- const result = < MLKitLandmarkRecognitionResult > {
24+ const result = < MLKitLandmarkRecognitionCloudResult > {
6425 landmarks : [ ]
6526 } ;
6627
@@ -77,7 +38,7 @@ export function recognizeLandmark(options: MLKitLandmarkRecognitionOptions): Pro
7738 }
7839 } ) ;
7940 } catch ( ex ) {
80- console . log ( "Error in firebase.mlkit.recognizeLandmark : " + ex ) ;
41+ console . log ( "Error in firebase.mlkit.recognizeLandmarksCloud : " + ex ) ;
8142 reject ( ex ) ;
8243 }
8344 } ) ;
0 commit comments