瀏覽代碼

Document and move

Manav Rathi 1 年之前
父節點
當前提交
a8229f325d
共有 2 個文件被更改,包括 22 次插入15 次删除
  1. 9 10
      web/apps/photos/src/services/face/f-index.ts
  2. 13 5
      web/apps/photos/src/services/face/types.ts

+ 9 - 10
web/apps/photos/src/services/face/f-index.ts

@@ -461,7 +461,14 @@ const faceAlignmentUsingSimilarityTransform = (
     const centerMat = simTransform.fromMean.sub(meanTranslation);
     const center = new Point(centerMat.get(0, 0), centerMat.get(1, 0));
 
-    return { affineMatrix, center, size };
+    const boundingBox = new Box({
+        x: center.x - size / 2,
+        y: center.y - size / 2,
+        width: size,
+        height: size,
+    });
+
+    return { affineMatrix, boundingBox };
 };
 
 const convertToMobileFaceNetInput = (
@@ -736,15 +743,7 @@ const extractFaceCrop = (
     imageBitmap: ImageBitmap,
     alignment: FaceAlignment,
 ): ImageBitmap => {
-    const alignmentBox = new Box({
-        x: alignment.center.x - alignment.size / 2,
-        y: alignment.center.y - alignment.size / 2,
-        width: alignment.size,
-        height: alignment.size,
-    });
-
-    const paddedBox = roundBox(enlargeBox(alignmentBox, 1.5));
-
+    const paddedBox = roundBox(enlargeBox(alignment.boundingBox, 1.5));
     const outputSize = { width: paddedBox.width, height: paddedBox.height };
 
     const maxDimension = 256;

+ 13 - 5
web/apps/photos/src/services/face/types.ts

@@ -8,12 +8,20 @@ export interface FaceDetection {
 }
 
 export interface FaceAlignment {
-    // An affine transformation matrix (rotation, translation, scaling) to align
-    // the face extracted from the image.
+    /**
+     * An affine transformation matrix (rotation, translation, scaling) to align
+     * the face extracted from the image.
+     */
     affineMatrix: number[][];
-    // size and center is relative to image dimentions stored at mlFileData
-    size: number;
-    center: Point;
+    /**
+     * The bounding box of the transformed box.
+     *
+     * The affine transformation shifts the original detection box a new,
+     * transformed, box (possibily rotated). This property is the bounding box
+     * of that transformed box. It is in the coordinate system of the original,
+     * full, image on which the detection occurred.
+     */
+    boundingBox: Box;
 }
 
 export interface Face {