11import { ImageSource } from "tns-core-modules/image-source" ;
2+ import { MLKitDetectFacesOnDeviceOptions , MLKitDetectFacesOnDeviceResult , MLKitDetectFacesResultBounds } from "./" ;
23import { MLKitVisionOptions } from "../" ;
3- import { MLKitDetectFacesOnDeviceOptions , MLKitDetectFacesOnDeviceResult } from "./" ;
44import { MLKitFaceDetection as MLKitFaceDetectionBase } from "./facedetection-common" ;
55
66const gmsTasks = ( < any > com . google . android . gms ) . tasks ;
@@ -33,10 +33,13 @@ export class MLKitFaceDetection extends MLKitFaceDetectionBase {
3333 for ( let i = 0 ; i < faces . size ( ) ; i ++ ) {
3434 const face = faces . get ( i ) ;
3535 result . faces . push ( {
36+ bounds : boundingBoxToBounds ( face . getBoundingBox ( ) ) ,
3637 smilingProbability : face . getSmilingProbability ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . UNCOMPUTED_PROBABILITY ? face . getSmilingProbability ( ) : undefined ,
3738 leftEyeOpenProbability : face . getLeftEyeOpenProbability ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . UNCOMPUTED_PROBABILITY ? face . getLeftEyeOpenProbability ( ) : undefined ,
3839 rightEyeOpenProbability : face . getRightEyeOpenProbability ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . UNCOMPUTED_PROBABILITY ? face . getRightEyeOpenProbability ( ) : undefined ,
39- trackingId : face . getTrackingId ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . INVALID_ID ? face . getTrackingId ( ) : undefined
40+ trackingId : face . getTrackingId ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . INVALID_ID ? face . getTrackingId ( ) : undefined ,
41+ headEulerAngleY : face . getHeadEulerAngleY ( ) ,
42+ headEulerAngleZ : face . getHeadEulerAngleZ ( )
4043 } ) ;
4144 }
4245
@@ -64,6 +67,19 @@ function getFaceDetector(options: MLKitDetectFacesOnDeviceOptions): any {
6467 return com . google . firebase . ml . vision . FirebaseVision . getInstance ( ) . getVisionFaceDetector ( builder . build ( ) ) ;
6568}
6669
70+ function boundingBoxToBounds ( rect : any ) : MLKitDetectFacesResultBounds {
71+ return {
72+ origin : {
73+ x : rect . left ,
74+ y : rect . top
75+ } ,
76+ size : {
77+ width : rect . width ( ) ,
78+ height : rect . height ( )
79+ }
80+ }
81+ }
82+
6783export function detectFacesOnDevice ( options : MLKitDetectFacesOnDeviceOptions ) : Promise < MLKitDetectFacesOnDeviceResult > {
6884 return new Promise ( ( resolve , reject ) => {
6985 try {
@@ -81,10 +97,13 @@ export function detectFacesOnDevice(options: MLKitDetectFacesOnDeviceOptions): P
8197 for ( let i = 0 ; i < faces . size ( ) ; i ++ ) {
8298 const face = faces . get ( i ) ;
8399 result . faces . push ( {
100+ bounds : boundingBoxToBounds ( face . getBoundingBox ( ) ) ,
84101 smilingProbability : face . getSmilingProbability ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . UNCOMPUTED_PROBABILITY ? face . getSmilingProbability ( ) : undefined ,
85102 leftEyeOpenProbability : face . getLeftEyeOpenProbability ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . UNCOMPUTED_PROBABILITY ? face . getLeftEyeOpenProbability ( ) : undefined ,
86103 rightEyeOpenProbability : face . getRightEyeOpenProbability ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . UNCOMPUTED_PROBABILITY ? face . getRightEyeOpenProbability ( ) : undefined ,
87- trackingId : face . getTrackingId ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . INVALID_ID ? face . getTrackingId ( ) : undefined
104+ trackingId : face . getTrackingId ( ) !== com . google . firebase . ml . vision . face . FirebaseVisionFace . INVALID_ID ? face . getTrackingId ( ) : undefined ,
105+ headEulerAngleY : face . getHeadEulerAngleY ( ) ,
106+ headEulerAngleZ : face . getHeadEulerAngleZ ( )
88107 } ) ;
89108 }
90109 }
0 commit comments