Browse Source

[mob] Method for detecting sideways faces

laurenspriem 1 năm trước cách đây
mục cha
commit
2b88daa15f

+ 25 - 0
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);
+  }
 }

+ 6 - 0
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}',