π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Show face direction in face widget in debug mode
laurenspriemb1eb6c11b2e8
diff --git a/mobile/lib/face/model/detection.dart b/mobile/lib/face/model/detection.dartindex cd7ff6c64f..0718340b27 100644--- a/mobile/lib/face/model/detection.dart+++ b/mobile/lib/face/model/detection.dart@@ -1,6 +1,9 @@+import "dart:math" show min, max;+import "package:logging/logging.dart";import "package:photos/face/model/box.dart";import "package:photos/face/model/landmark.dart";+import "package:photos/services/machine_learning/face_ml/face_detection/detection.dart";/// Stores the face detection data, notably the bounding box and landmarks.///@@ -89,4 +92,41 @@ class Detection {return -1;}}++ FaceDirection getFaceDirection() {+ final leftEye = [landmarks[0].x, landmarks[0].y];+ final rightEye = [landmarks[1].x, landmarks[1].y];+ final nose = [landmarks[2].x, landmarks[2].y];+ final leftMouth = [landmarks[3].x, landmarks[3].y];+ final rightMouth = [landmarks[4].x, landmarks[4].y];++ final double eyeDistanceX = (rightEye[0] - leftEye[0]).abs();+ final double eyeDistanceY = (rightEye[1] - leftEye[1]).abs();+ final double mouthDistanceY = (rightMouth[1] - leftMouth[1]).abs();++ final bool faceIsUpright =+ (max(leftEye[1], rightEye[1]) + 0.5 * eyeDistanceY < nose[1]) &&+ (nose[1] + 0.5 * mouthDistanceY < min(leftMouth[1], rightMouth[1]));++ final bool noseStickingOutLeft = (nose[0] < min(leftEye[0], rightEye[0])) &&+ (nose[0] < min(leftMouth[0], rightMouth[0]));+ final bool noseStickingOutRight =+ (nose[0] > max(leftEye[0], rightEye[0])) &&+ (nose[0] > max(leftMouth[0], rightMouth[0]));++ final bool noseCloseToLeftEye =+ (nose[0] - leftEye[0]).abs() < 0.2 * eyeDistanceX;+ final bool noseCloseToRightEye =+ (nose[0] - rightEye[0]).abs() < 0.2 * eyeDistanceX;++ // if (faceIsUpright && (noseStickingOutLeft || noseCloseToLeftEye)) {+ if (noseStickingOutLeft || (faceIsUpright && noseCloseToLeftEye)) {+ return FaceDirection.left;+ // } else if (faceIsUpright && (noseStickingOutRight || noseCloseToRightEye)) {+ } else if (noseStickingOutRight || (faceIsUpright && noseCloseToRightEye)) {+ return FaceDirection.right;+ }++ return FaceDirection.straight;+ }}diff --git a/mobile/lib/services/machine_learning/face_ml/face_detection/detection.dart b/mobile/lib/services/machine_learning/face_ml/face_detection/detection.dartindex c63ef51c20..7e74f872ef 100644--- a/mobile/lib/services/machine_learning/face_ml/face_detection/detection.dart+++ b/mobile/lib/services/machine_learning/face_ml/face_detection/detection.dart@@ -8,11 +8,11 @@ extension FaceDirectionExtension on FaceDirection {String toDirectionString() {switch (this) {case FaceDirection.left:- return 'L';+ return 'Left';case FaceDirection.right:- return 'R';+ return 'Right';case FaceDirection.straight:- return 'S';+ return 'Straigt';default:throw Exception('Unknown FaceDirection');}diff --git a/mobile/lib/ui/viewer/file_details/face_widget.dart b/mobile/lib/ui/viewer/file_details/face_widget.dartindex 0fe8958e34..c33004eff4 100644--- a/mobile/lib/ui/viewer/file_details/face_widget.dart+++ b/mobile/lib/ui/viewer/file_details/face_widget.dart@@ -9,6 +9,7 @@ import "package:photos/face/db.dart";import "package:photos/face/model/face.dart";import "package:photos/face/model/person.dart";import 'package:photos/models/file/file.dart';+import "package:photos/services/machine_learning/face_ml/face_detection/detection.dart";import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";import "package:photos/services/search_service.dart";import "package:photos/theme/ente_theme.dart";@@ -168,6 +169,12 @@ class _FaceWidgetState extends State<FaceWidget> {style: Theme.of(context).textTheme.bodySmall,maxLines: 1,),+ if (kDebugMode)+ Text(+ 'D: ${widget.face.detection.getFaceDirection().toDirectionString()}',+ style: Theme.of(context).textTheme.bodySmall,+ maxLines: 1,+ ),if (kDebugMode)Text('V: ${widget.face.visibility}',