diff --git a/demo/app/app.css b/demo/app/app.css index e7394b8a..81e53074 100644 --- a/demo/app/app.css +++ b/demo/app/app.css @@ -82,8 +82,7 @@ button { } .barcodescanner { - width: 320; - height: 260; + height: 420; margin-top: 16; } diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index 6b679cee..e425b747 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -3,6 +3,7 @@ import * as pages from 'tns-core-modules/ui/page'; import { HelloWorldModel } from './main-view-model'; import { MLKitRecognizeTextResult } from "nativescript-plugin-firebase/mlkit/textrecognition"; import { MLKitScanBarcodesResult } from "nativescript-plugin-firebase/mlkit/barcodescanning"; +import { MLKitDetectFacesResult } from "nativescript-plugin-firebase/mlkit/facedetection"; const model = new HelloWorldModel(); @@ -24,5 +25,30 @@ export function onBarcodesScanResult(scanResult: any) { export function onTextRecognitionResult(scanResult: any) { const value: MLKitRecognizeTextResult = scanResult.value; - model.set("textValue", value.features.map(feature => feature.text).join("\n")); + model.set("textValue", value.features.map(feature => feature.text).join("\n\n")); +} + +export function onFaceDetectionResult(scanResult: any) { + const value: MLKitDetectFacesResult = scanResult.value; + if (value.faces.length > 0) { + let allSmilingAndEyesOpen = true; + value.faces.forEach(face => { + allSmilingAndEyesOpen = allSmilingAndEyesOpen && face.smilingProbability && face.leftEyeOpenProbability && face.rightEyeOpenProbability && + face.smilingProbability > 0.7 && face.leftEyeOpenProbability > 0.7 && face.rightEyeOpenProbability > 0.7; + }); + model.set("allOK", `All smiling and eyes open? ${allSmilingAndEyesOpen ? 'Yes, screen grabbed:' : 'Nope. Sad.'}`); + // model.set("textValue", value.faces.map(face => JSON.stringify(face)).join("\n")); + model.set("textValue", value.faces.map(face => `Smiling? ${round(face.smilingProbability)}%\nLeft eye open? ${round(face.leftEyeOpenProbability)}%\nRight eye open? ${round(face.rightEyeOpenProbability)}%`).join("\n\n")); + + if (allSmilingAndEyesOpen && value.imageSource) { + model.set("lastMatch", value.imageSource); + } + } +} + +function round (input) { + if (isNaN(input)) { + return 0; + } + return Math.round(input * 100); } diff --git a/demo/app/main-page.xml b/demo/app/main-page.xml index 34c88e19..d73f8ae6 100644 --- a/demo/app/main-page.xml +++ b/demo/app/main-page.xml @@ -1,4 +1,8 @@ - + @@ -146,11 +150,24 @@ class="barcodescanner" scanResult="onBarcodesScanResult" /> - - + + +