Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 2ebd2f1

Browse files
committed
Added bounds to MLKitDetectFacesResultFace
1 parent 48a99cc commit 2ebd2f1

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/mlkit/facedetection/index.android.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImageSource } from "tns-core-modules/image-source";
2-
import { MLKitDetectFacesOnDeviceOptions, MLKitDetectFacesOnDeviceResult } from "./";
2+
import { MLKitDetectFacesOnDeviceOptions, MLKitDetectFacesOnDeviceResult, MLKitDetectFacesResultBounds } from "./";
33
import { MLKitOptions } from "../index";
44
import { MLKitFaceDetection as MLKitFaceDetectionBase } from "./facedetection-common";
55

@@ -63,6 +63,19 @@ function getFaceDetector(options: MLKitDetectFacesOnDeviceOptions): any {
6363
return com.google.firebase.ml.vision.FirebaseVision.getInstance().getVisionFaceDetector(faceDetectorOptions);
6464
}
6565

66+
function boundingBoxToBounds(rect: any): MLKitDetectFacesResultBounds {
67+
return {
68+
origin: {
69+
x: rect.left,
70+
y: rect.top
71+
},
72+
size: {
73+
width: rect.width(),
74+
height: rect.height()
75+
}
76+
}
77+
}
78+
6679
export function detectFacesOnDevice(options: MLKitDetectFacesOnDeviceOptions): Promise<MLKitDetectFacesOnDeviceResult> {
6780
return new Promise((resolve, reject) => {
6881
try {
@@ -80,6 +93,7 @@ export function detectFacesOnDevice(options: MLKitDetectFacesOnDeviceOptions): P
8093
for (let i = 0; i < faces.size(); i++) {
8194
const face = faces.get(i);
8295
result.faces.push({
96+
bounds: boundingBoxToBounds(face.getBoundingBox()),
8397
smilingProbability: face.getSmilingProbability() !== com.google.firebase.ml.vision.face.FirebaseVisionFace.UNCOMPUTED_PROBABILITY ? face.getSmilingProbability() : undefined,
8498
leftEyeOpenProbability: face.getLeftEyeOpenProbability() !== com.google.firebase.ml.vision.face.FirebaseVisionFace.UNCOMPUTED_PROBABILITY ? face.getLeftEyeOpenProbability() : undefined,
8599
rightEyeOpenProbability: face.getRightEyeOpenProbability() !== com.google.firebase.ml.vision.face.FirebaseVisionFace.UNCOMPUTED_PROBABILITY ? face.getRightEyeOpenProbability() : undefined,

src/mlkit/facedetection/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import { MLKitOptions } from "../";
22
import { MLKitCameraView, MLKitResult } from "../index";
33

4+
export interface MLKitDetectFacesResultBounds {
5+
origin: {
6+
x: number;
7+
y: number;
8+
},
9+
size: {
10+
width: number;
11+
height: number;
12+
}
13+
}
14+
415
export interface MLKitDetectFacesResultFace {
516
smilingProbability?: number;
617
leftEyeOpenProbability?: number;
718
rightEyeOpenProbability?: number;
819
trackingId?: number;
920
ios?: any;
1021
android?: any;
22+
bounds?: MLKitDetectFacesResultBounds;
1123
}
1224

1325
export interface MLKitDetectFacesOnDeviceResult extends MLKitResult {

src/mlkit/facedetection/index.ios.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export class MLKitFaceDetection extends MLKitFaceDetectionBase {
3131
smilingProbability: face.hasSmilingProbability ? face.smilingProbability : undefined,
3232
leftEyeOpenProbability: face.hasLeftEyeOpenProbability ? face.leftEyeOpenProbability : undefined,
3333
rightEyeOpenProbability: face.hasRightEyeOpenProbability ? face.rightEyeOpenProbability : undefined,
34-
trackingId: face.hasTrackingID ? face.trackingID : undefined
34+
trackingId: face.hasTrackingID ? face.trackingID : undefined,
35+
bounds: face.frame
3536
});
3637
}
3738

0 commit comments

Comments
 (0)