Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob] Method for detecting sideways faces

laurenspriem2b88daa15fd7
diff --git a/mobile/lib/face/model/detection.dart b/mobile/lib/face/model/detection.dart
index 0718340b27..af6324ac85 100644
--- a/mobile/lib/face/model/detection.dart
+++ b/mobile/lib/face/model/detection.dart
@@ -129,4 +129,29 @@ class Detection {
return FaceDirection.straight;
}
+
+ bool faceIsSideways() {
+ 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]) - 0.5 * eyeDistanceX) &&
+ (nose[0] < min(leftMouth[0], rightMouth[0]));
+ final bool noseStickingOutRight =
+ (nose[0] > max(leftEye[0], rightEye[0]) - 0.5 * eyeDistanceX) &&
+ (nose[0] > max(leftMouth[0], rightMouth[0]));
+
+ return faceIsUpright && (noseStickingOutLeft || noseStickingOutRight);
+ }
}
diff --git a/mobile/lib/ui/viewer/file_details/face_widget.dart b/mobile/lib/ui/viewer/file_details/face_widget.dart
index c33004eff4..980049134d 100644
--- a/mobile/lib/ui/viewer/file_details/face_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/face_widget.dart
@@ -175,6 +175,12 @@ class _FaceWidgetState extends State<FaceWidget> {
style: Theme.of(context).textTheme.bodySmall,
maxLines: 1,
),
+ if (kDebugMode)
+ Text(
+ 'Sideways: ${widget.face.detection.faceIsSideways().toString()}',
+ style: Theme.of(context).textTheme.bodySmall,
+ maxLines: 1,
+ ),
if (kDebugMode)
Text(
'V: ${widget.face.visibility}',