Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Put x and y instead of xMin and yMin in embeddingsJSON

laurenspriem1b46e159da60
diff --git a/mobile/lib/face/model/box.dart b/mobile/lib/face/model/box.dart
index 73d7dea388..3c5be3f9f3 100644
--- a/mobile/lib/face/model/box.dart
+++ b/mobile/lib/face/model/box.dart
@@ -1,42 +1,34 @@
/// Bounding box of a face.
///
-/// [xMin] and [yMin] are the coordinates of the top left corner of the box, and
+/// [ x] and [y] are the minimum coordinates, so the top left corner of the box.
/// [width] and [height] are the width and height of the box.
///
/// WARNING: All values are relative to the original image size, so in the range [0, 1].
class FaceBox {
- final double xMin;
- final double yMin;
+ final double x;
+ final double y;
final double width;
final double height;
FaceBox({
- required this.xMin,
- required this.yMin,
+ required this.x,
+ required this.y,
required this.width,
required this.height,
});
factory FaceBox.fromJson(Map<String, dynamic> json) {
return FaceBox(
- xMin: (json['xMin'] is int
- ? (json['xMin'] as int).toDouble()
- : json['xMin'] as double),
- yMin: (json['yMin'] is int
- ? (json['yMin'] as int).toDouble()
- : json['yMin'] as double),
- width: (json['width'] is int
- ? (json['width'] as int).toDouble()
- : json['width'] as double),
- height: (json['height'] is int
- ? (json['height'] as int).toDouble()
- : json['height'] as double),
+ x: (json['x'] as double?) ?? (json['xMin'] as double),
+ y: (json['y'] as double?) ?? (json['yMin'] as double),
+ width: json['width'] as double,
+ height: json['height'] as double,
);
}
Map<String, dynamic> toJson() => {
- 'xMin': xMin,
- 'yMin': yMin,
+ 'x': x,
+ 'y': y,
'width': width,
'height': height,
};
diff --git a/mobile/lib/face/model/detection.dart b/mobile/lib/face/model/detection.dart
index 6fc5fa07b1..44329196a4 100644
--- a/mobile/lib/face/model/detection.dart
+++ b/mobile/lib/face/model/detection.dart
@@ -6,7 +6,7 @@ import "package:photos/services/machine_learning/face_ml/face_detection/detectio
/// Stores the face detection data, notably the bounding box and landmarks.
///
-/// - Bounding box: [FaceBox] with xMin, yMin (so top left corner), width, height
+/// - Bounding box: [FaceBox] with x, y (minimum, so top left corner), width, height
/// - Landmarks: list of [Landmark]s, namely leftEye, rightEye, nose, leftMouth, rightMouth
///
/// WARNING: All coordinates are relative to the image size, so in the range [0, 1]!
@@ -24,8 +24,8 @@ class Detection {
// empty box
Detection.empty()
: box = FaceBox(
- xMin: 0,
- yMin: 0,
+ x: 0,
+ y: 0,
width: 0,
height: 0,
),
diff --git a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart
index 0bfbfcd224..cefb496ae0 100644
--- a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart
+++ b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart
@@ -793,8 +793,8 @@ class FaceMlService {
final FaceResult faceRes = result.faces[i];
final detection = face_detection.Detection(
box: FaceBox(
- xMin: faceRes.detection.xMinBox,
- yMin: faceRes.detection.yMinBox,
+ x: faceRes.detection.xMinBox,
+ y: faceRes.detection.yMinBox,
width: faceRes.detection.width,
height: faceRes.detection.height,
),
diff --git a/mobile/lib/ui/viewer/people/cropped_face_image_view.dart b/mobile/lib/ui/viewer/people/cropped_face_image_view.dart
index 823a979fcd..a76dbe5f0a 100644
--- a/mobile/lib/ui/viewer/people/cropped_face_image_view.dart
+++ b/mobile/lib/ui/viewer/people/cropped_face_image_view.dart
@@ -49,10 +49,8 @@ class CroppedFaceImageView extends StatelessWidget {
final faceBox = face.detection.box;
- final double relativeFaceCenterX =
- faceBox.xMin + faceBox.width / 2;
- final double relativeFaceCenterY =
- faceBox.yMin + faceBox.height / 2;
+ final double relativeFaceCenterX = faceBox.x + faceBox.width / 2;
+ final double relativeFaceCenterY = faceBox.y + faceBox.height / 2;
const double desiredFaceHeightRelativeToWidget = 8 / 10;
final double scale =
diff --git a/mobile/lib/utils/face/face_util.dart b/mobile/lib/utils/face/face_util.dart
index c49d57b408..56dc8f3bf0 100644
--- a/mobile/lib/utils/face/face_util.dart
+++ b/mobile/lib/utils/face/face_util.dart
@@ -110,8 +110,8 @@ FaceBoxImage _getSquareFaceBoxImage(img.Image image, FaceBox faceBox) {
final width = (image.width * faceBox.width).round();
final height = (image.height * faceBox.height).round();
final side = max(width, height);
- final xImage = (image.width * faceBox.xMin).round();
- final yImage = (image.height * faceBox.yMin).round();
+ final xImage = (image.width * faceBox.x).round();
+ final yImage = (image.height * faceBox.y).round();
if (height >= width) {
final xImageAdj = (xImage - (height - width) / 2).round();
diff --git a/mobile/lib/utils/image_ml_util.dart b/mobile/lib/utils/image_ml_util.dart
index 8a60517937..916b9099cd 100644
--- a/mobile/lib/utils/image_ml_util.dart
+++ b/mobile/lib/utils/image_ml_util.dart
@@ -559,6 +559,7 @@ Future<Image> cropImageWithCanvasSimple(
}
@Deprecated('Old image processing method, use `cropImage` instead!')
+
/// Crops an [image] based on the specified [x], [y], [width] and [height].
/// Optionally, the cropped image can be resized to comply with a [maxSize] and/or [minSize].
/// Optionally, the cropped image can be rotated from the center by [rotation] radians.
@@ -1276,8 +1277,8 @@ Future<List<Uint8List>> generateFaceThumbnails(
for (final faceBox in faceBoxes) {
// Note that the faceBox values are relative to the image size, so we need to convert them to absolute values first
- final double xMinAbs = faceBox.xMin * img.width;
- final double yMinAbs = faceBox.yMin * img.height;
+ final double xMinAbs = faceBox.x * img.width;
+ final double yMinAbs = faceBox.y * img.height;
final double widthAbs = faceBox.width * img.width;
final double heightAbs = faceBox.height * img.height;
@@ -1323,8 +1324,8 @@ Future<List<Uint8List>> generateFaceThumbnailsUsingCanvas(
final futureFaceThumbnails = <Future<Uint8List>>[];
for (final faceBox in faceBoxes) {
// Note that the faceBox values are relative to the image size, so we need to convert them to absolute values first
- final double xMinAbs = faceBox.xMin * img.width;
- final double yMinAbs = faceBox.yMin * img.height;
+ final double xMinAbs = faceBox.x * img.width;
+ final double yMinAbs = faceBox.y * img.height;
final double widthAbs = faceBox.width * img.width;
final double heightAbs = faceBox.height * img.height;