Manav Rathi 1 년 전
부모
커밋
39a75430a5
3개의 변경된 파일14개의 추가작업 그리고 13개의 파일을 삭제
  1. 9 4
      web/apps/photos/src/services/face/f-index.ts
  2. 0 4
      web/apps/photos/src/services/face/geom.ts
  3. 5 5
      web/apps/photos/src/services/face/transform-box.ts

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

@@ -4,7 +4,7 @@ import log from "@/next/log";
 import { workerBridge } from "@/next/worker/worker-bridge";
 import { euclidean } from "hdbscan";
 import { Matrix } from "ml-matrix";
-import { Box, Dimensions, Point, enlargeBox, newBox } from "services/face/geom";
+import { Box, Dimensions, Point, enlargeBox } from "services/face/geom";
 import {
     DetectedFace,
     Face,
@@ -143,13 +143,18 @@ const indexFaces_ = async (enteFile: EnteFile, imageBitmap: ImageBitmap) => {
 const detectFaces = async (
     imageBitmap: ImageBitmap,
 ): Promise<Array<FaceDetection>> => {
+    const rect = ({ width, height }: { width: number; height: number }) =>
+        new Box({ x: 0, y: 0, width, height });
+
     const { yoloInput, yoloSize } =
         convertToYOLOInputFloat32ChannelsFirst(imageBitmap);
     const yoloOutput = await workerBridge.detectFaces(yoloInput);
     const faces = faceDetectionsFromYOLOOutput(yoloOutput);
-    const inBox = newBox(0, 0, yoloSize.width, yoloSize.height);
-    const toBox = newBox(0, 0, imageBitmap.width, imageBitmap.height);
-    const faceDetections = transformFaceDetections(faces, inBox, toBox);
+    const faceDetections = transformFaceDetections(
+        faces,
+        rect(yoloSize),
+        rect(imageBitmap),
+    );
 
     const maxFaceDistancePercent = Math.sqrt(2) / 100;
     const maxFaceDistance = imageBitmap.width * maxFaceDistancePercent;

+ 0 - 4
web/apps/photos/src/services/face/geom.ts

@@ -27,10 +27,6 @@ export interface IRect {
     height: number;
 }
 
-export function newBox(x: number, y: number, width: number, height: number) {
-    return new Box({ x, y, width, height });
-}
-
 export const boxFromBoundingBox = ({
     left,
     top,

+ 5 - 5
web/apps/photos/src/services/face/transform-box.ts

@@ -13,17 +13,17 @@ import {
 } from "transformation-matrix";
 
 /**
- * Detect faces in the given {@link imageBitmap}.
- *
- * The model used is YOLO, running in an ONNX runtime.
+ * Transform the given {@link faceDetections} from their coordinate system in
+ * which they were detected ({@link inBox}) back to the coordinate system of the
+ * original image ({@link toBox}).
  */
 export const transformFaceDetections = (
-    faces: FaceDetection[],
+    faceDetections: FaceDetection[],
     inBox: Box,
     toBox: Box,
 ): FaceDetection[] => {
     const transform = computeTransformToBox(inBox, toBox);
-    return faces.map((f) => {
+    return faceDetections.map((f) => {
         const box = transformBox(f.box, transform);
         const normLandmarks = f.landmarks;
         const landmarks = transformPoints(normLandmarks, transform);